diff --git a/nautobot-app-chatops/{{ cookiecutter.project_slug }}/development/check_migrations.py b/nautobot-app-chatops/{{ cookiecutter.project_slug }}/development/check_migrations.py new file mode 120000 index 00000000..4658536d --- /dev/null +++ b/nautobot-app-chatops/{{ cookiecutter.project_slug }}/development/check_migrations.py @@ -0,0 +1 @@ +nautobot-app/{{ cookiecutter.project_slug }}/development/check_migrations.py \ No newline at end of file diff --git a/nautobot-app-ssot/{{ cookiecutter.project_slug }}/development/check_migrations.py b/nautobot-app-ssot/{{ cookiecutter.project_slug }}/development/check_migrations.py new file mode 120000 index 00000000..4658536d --- /dev/null +++ b/nautobot-app-ssot/{{ cookiecutter.project_slug }}/development/check_migrations.py @@ -0,0 +1 @@ +nautobot-app/{{ cookiecutter.project_slug }}/development/check_migrations.py \ No newline at end of file diff --git a/nautobot-app/{{ cookiecutter.project_slug }}/development/check_migrations.py b/nautobot-app/{{ cookiecutter.project_slug }}/development/check_migrations.py new file mode 100644 index 00000000..bc0670b2 --- /dev/null +++ b/nautobot-app/{{ cookiecutter.project_slug }}/development/check_migrations.py @@ -0,0 +1,20 @@ +"""This is a helper script meant for celery beat to check for migrations. The beat +error log is too large and hides from your terminal the most common case in which you +will have issues with the migrations or around the same time migrations are running.""" + +import time +from django.db import ProgrammingError +import nautobot + +nautobot.setup() + +from nautobot.extras.models.jobs import ScheduledJob + +while True: + try: + list(ScheduledJob.objects.all()) + print("Migrations are complete, proceeding.") + break + except ProgrammingError: + print("Migrations not complete yet, retrying in 5 seconds...") + time.sleep(5) # Wait for a few seconds before retrying \ No newline at end of file diff --git a/nautobot-app/{{ cookiecutter.project_slug }}/development/docker-compose.dev.yml b/nautobot-app/{{ cookiecutter.project_slug }}/development/docker-compose.dev.yml index 594ac22a..10c580ce 100644 --- a/nautobot-app/{{ cookiecutter.project_slug }}/development/docker-compose.dev.yml +++ b/nautobot-app/{{ cookiecutter.project_slug }}/development/docker-compose.dev.yml @@ -41,10 +41,13 @@ services: entrypoint: - "sh" - "-c" # this is to evaluate the $NAUTOBOT_LOG_LEVEL from the env - - "watchmedo auto-restart --directory './' --pattern '*.py' --recursive -- nautobot-server celery beat -l $$NAUTOBOT_LOG_LEVEL" ## $$ because of docker-compose + - | + python /opt/nautobot/check_migrations.py && \ + "watchmedo auto-restart --directory './' --pattern '*.py' --recursive -- nautobot-server celery beat -l WARNING" volumes: - "./nautobot_config.py:/opt/nautobot/nautobot_config.py" - "../:/source" + - "./check_migrations.py:/opt/nautobot/check_migrations.py" # To expose postgres or redis to the host uncomment the following # postgres: # ports: