mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
dev: hold celery worker and beat when pending migrations
This commit is contained in:
parent
e43139726f
commit
dd95dd9f5e
@ -2,4 +2,5 @@
|
||||
set -e
|
||||
|
||||
python manage.py wait_for_db
|
||||
python manage.py wait_for_migrations
|
||||
celery -A plane beat -l info
|
@ -2,4 +2,5 @@
|
||||
set -e
|
||||
|
||||
python manage.py wait_for_db
|
||||
python manage.py wait_for_migrations
|
||||
celery -A plane worker -l info
|
@ -0,0 +1,21 @@
|
||||
# wait_for_migrations.py
|
||||
import time
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db.migrations.executor import MigrationExecutor
|
||||
from django.db import connections, DEFAULT_DB_ALIAS
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Wait for database migrations to complete before starting Celery worker/beat'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
while self._pending_migrations():
|
||||
self.stdout.write("Waiting for database migrations to complete...")
|
||||
time.sleep(10) # wait for 10 seconds before checking again
|
||||
|
||||
self.stdout.write("All migrations are complete. Safe to start Celery worker/beat.")
|
||||
|
||||
def _pending_migrations(self):
|
||||
connection = connections[DEFAULT_DB_ALIAS]
|
||||
executor = MigrationExecutor(connection)
|
||||
targets = executor.loader.graph.leaf_nodes()
|
||||
return bool(executor.migration_plan(targets))
|
Loading…
Reference in New Issue
Block a user