24 lines
928 B
Python
24 lines
928 B
Python
from django.apps import AppConfig
|
|
|
|
|
|
class AppConfig(AppConfig):
|
|
default_auto_field = 'django.db.models.BigAutoField'
|
|
name = 'app'
|
|
|
|
def ready(self):
|
|
import app.workflow_actions
|
|
from . import signals
|
|
signals.connect_signals()
|
|
|
|
# Sử dụng cache.add() của Django để tạo lock, đảm bảo chỉ một worker khởi động scheduler
|
|
try:
|
|
from django.core.cache import cache
|
|
# cache.add() là atomic, chỉ trả về True nếu key được tạo thành công
|
|
if cache.add("scheduler_lock", "locked", timeout=65):
|
|
from . import scheduler
|
|
scheduler.start()
|
|
print("Scheduler started by this worker.")
|
|
else:
|
|
print("Scheduler lock already held by another worker.")
|
|
except Exception as e:
|
|
print(f"Failed to start or check scheduler lock: {e}") |