diff --git a/operations/apps.py b/operations/apps.py index c48a8f9a..7e3c3da4 100644 --- a/operations/apps.py +++ b/operations/apps.py @@ -1,21 +1,10 @@ from django.apps import AppConfig -from django.db.backends.signals import connection_created - - -def _sqlite_wal(sender, connection, **kwargs): - """The worker and gunicorn write the same SQLite file: WAL lets readers - go on during a write. Django's SQLite OPTIONS have no init command.""" - if connection.vendor == "sqlite": - with connection.cursor() as cursor: - cursor.execute("PRAGMA journal_mode=WAL") class OperationsConfig(AppConfig): - default_auto_field = "django.db.models.BigAutoField" name = "operations" def ready(self): - connection_created.connect(_sqlite_wal) # every installed app's jobs.py registers its kinds from django.utils.module_loading import autodiscover_modules diff --git a/webvirtcloud/settings.py.template b/webvirtcloud/settings.py.template index 5cbb9c68..2d4b6382 100644 --- a/webvirtcloud/settings.py.template +++ b/webvirtcloud/settings.py.template @@ -161,9 +161,9 @@ else: "NAME": Path.joinpath(BASE_DIR, "db.sqlite3"), # IMMEDIATE takes the write lock when a transaction starts, so a # check-then-write cannot interleave with another process; timeout - # is how long a writer waits for that lock (seconds). WAL is set - # per connection by the operations app. - "OPTIONS": {"transaction_mode": "IMMEDIATE", "timeout": 20}, + # is how long a writer waits for that lock (seconds). WAL lets the + # worker and gunicorn read while one of them writes. + "OPTIONS": {"transaction_mode": "IMMEDIATE", "timeout": 20, "init_command": "PRAGMA journal_mode=WAL"}, # A file, not shared-cache memory: test threads and worker processes # open the same database, and shared-cache locks ignore the timeout. "TEST": {"NAME": os.getenv("WEBVIRTCLOUD_TEST_DB") or Path.joinpath(BASE_DIR, "test_db.sqlite3")},