From 25cd8ea72b8dd3e017ddac738373ab64ce934524 Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Tue, 14 Apr 2020 15:05:53 -0400 Subject: [PATCH] Update beat start files with better? SQL statement --- .../compose/local/django/celery/beat/start | 13 +++++++------ .../compose/production/django/celery/beat/start | 12 +++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/{{cookiecutter.project_slug}}/compose/local/django/celery/beat/start b/{{cookiecutter.project_slug}}/compose/local/django/celery/beat/start index 2499f866..477dfca3 100644 --- a/{{cookiecutter.project_slug}}/compose/local/django/celery/beat/start +++ b/{{cookiecutter.project_slug}}/compose/local/django/celery/beat/start @@ -22,17 +22,18 @@ try: # If not, wait for docker-compose up to migrate all tables. cur = conn.cursor() cur.execute( - "select exists(select * from ${POSTGRES_DB}.tables where table_name=%s)", + "select exists(select * from information_schema.tables where table_name=%s)", ('django_celery_beat_periodictask',) ) - conn.close() + if cur.fetchone()[0] == 1: + cur.close() + sys.exit(0) + else: + cur.close() + sys.exit(-1) except psycopg2.OperationalError: sys.exit(-1) -except psycopg2.errors.UndefinedTable: - conn.close() - sys.exit(-1) -sys.exit(0) END } until postgres_ready; do diff --git a/{{cookiecutter.project_slug}}/compose/production/django/celery/beat/start b/{{cookiecutter.project_slug}}/compose/production/django/celery/beat/start index 3882e194..0cc8ae8a 100644 --- a/{{cookiecutter.project_slug}}/compose/production/django/celery/beat/start +++ b/{{cookiecutter.project_slug}}/compose/production/django/celery/beat/start @@ -20,15 +20,17 @@ try: # If not, wait for docker-compose up to migrate all tables. cur = conn.cursor() cur.execute( - "select exists(select * from ${POSTGRES_DB}.tables where table_name=%s)", + "select exists(select * from information_schema.tables where table_name=%s)", ('django_celery_beat_periodictask',) ) - conn.close() + if cur.fetchone()[0] == 1: + cur.close() + sys.exit(0) + else: + cur.close() + sys.exit(-1) except psycopg2.OperationalError: sys.exit(-1) -except psycopg2.errors.UndefinedTable: - conn.close() - sys.exit(-1) sys.exit(0) END