From 4edec5f666eb1e9a835fbb7cc3fd8ef8287e918a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 19 Jul 2022 09:23:43 +0200 Subject: [PATCH] lifecycle: connect to database first Signed-off-by: Jens Langhammer --- lifecycle/migrate.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lifecycle/migrate.py b/lifecycle/migrate.py index 898faa0ea..1687171fd 100755 --- a/lifecycle/migrate.py +++ b/lifecycle/migrate.py @@ -53,15 +53,11 @@ def release_lock(): def is_locked(): """Check if lock is currently active (used by worker to wait for migrations)""" - curr.executor("SELECT count(*) FROM pg_locks WHERE objid = %s", (ADV_LOCK_UID,)) - return curr.rowcount + curr.execute("SELECT count(*) FROM pg_locks WHERE objid = %s", (ADV_LOCK_UID,)) + return curr.fetchall()[0][0] if __name__ == "__main__": - if len(sys.argv) > 1: - if sys.argv[1] == "check_lock": - sys.exit(is_locked()) - conn = connect( dbname=CONFIG.y("postgresql.name"), user=CONFIG.y("postgresql.user"), @@ -70,6 +66,10 @@ if __name__ == "__main__": port=int(CONFIG.y("postgresql.port")), ) curr = conn.cursor() + if len(sys.argv) > 1: + if sys.argv[1] == "check_lock": + sys.exit(is_locked()) + try: for migration in Path(__file__).parent.absolute().glob("system_migrations/*.py"): spec = spec_from_file_location("lifecycle.system_migrations", migration)