From 125f4333c2c3b0803e3838e5cd00bed5a60e2fef Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Thu, 22 Jun 2023 14:20:35 +0300 Subject: [PATCH] Merge pull request #698 from opengisch/QF-2638-master-node Ensure connection to the master node as soon as we have the DB session --- .../qfieldcloud/core/management/commands/dequeue.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docker-app/qfieldcloud/core/management/commands/dequeue.py b/docker-app/qfieldcloud/core/management/commands/dequeue.py index efa8d863e..05011de66 100644 --- a/docker-app/qfieldcloud/core/management/commands/dequeue.py +++ b/docker-app/qfieldcloud/core/management/commands/dequeue.py @@ -48,6 +48,15 @@ def handle(self, *args, **options): cancel_orphaned_workers() + with connection.cursor() as cursor: + # NOTE `pg_is_in_recovery` returns `FALSE` if connected to the master node + cursor.execute("SELECT pg_is_in_recovery()") + # there is no way `cursor.fetchone()` returns no rows, therefore ignore the type warning + if cursor.fetchone()[0]: # type: ignore + raise Exception( + "Expected `worker_wrapper` to be connected to the master DB node!" + ) + queued_job = None with transaction.atomic():