Skip to content

Commit 8224b29

Browse files
committed
feat(api): Move Celery Beat schedule configuration
1 parent e5a4fc7 commit 8224b29

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

cmdb-api/api/tasks/cmdb.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,22 @@ def counter_daily():
495495
raise
496496
finally:
497497
db.session.close()
498+
499+
500+
# Beat schedule for CMDB tasks
501+
from celery.schedules import crontab
502+
503+
CMDB_BEAT_SCHEDULE = {
504+
'cmdb-counter-main': {
505+
'task': 'cmdb.counter_main',
506+
'schedule': crontab(minute='*'),
507+
},
508+
'cmdb-counter-adc': {
509+
'task': 'cmdb.counter_adc',
510+
'schedule': crontab(minute='*/5'),
511+
},
512+
'cmdb-counter-daily': {
513+
'task': 'cmdb.counter_daily',
514+
'schedule': crontab(hour=0, minute=0),
515+
},
516+
}

cmdb-api/celery_worker.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,14 @@
22

33
from api.app import create_app
44
from api.extensions import celery
5-
from celery.schedules import crontab
65

76
# celery -A celery_worker.celery worker -l DEBUG -E -Q xxxx
87

98
app = create_app()
109
app.app_context().push()
1110

12-
# Beat schedule configuration
13-
celery.conf.beat_schedule = {
14-
'cmdb-counter-main': {
15-
'task': 'cmdb.counter_main',
16-
'schedule': crontab(minute='*'),
17-
},
18-
'cmdb-counter-adc': {
19-
'task': 'cmdb.counter_adc',
20-
'schedule': crontab(minute='*/5'),
21-
},
22-
'cmdb-counter-daily': {
23-
'task': 'cmdb.counter_daily',
24-
'schedule': crontab(hour=0, minute=0),
25-
},
26-
}
11+
# Load beat schedules from all modules
12+
from api.tasks.cmdb import CMDB_BEAT_SCHEDULE
13+
14+
celery.conf.beat_schedule = celery.conf.get('beat_schedule', {})
15+
celery.conf.beat_schedule.update(CMDB_BEAT_SCHEDULE)

0 commit comments

Comments
 (0)