-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcworker.py
More file actions
42 lines (33 loc) · 1.02 KB
/
cworker.py
File metadata and controls
42 lines (33 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
from celery import Celery
from app import create_app
from datetime import timedelta
from celery.schedules import crontab
app = create_app(os.getenv('APP_SETTINGS') or 'default')
def make_celery(app):
celery = Celery(
app.import_name,
broker=app.config['CELERY_BROKER_URL']
)
celery.conf.update(app.config)
class ContextTask(celery.Task):
def __call__(self, *args, **kwargs):
with app.app_context():
return self.run(*args, **kwargs)
celery.Task = ContextTask
return celery
app.config.update(
CELERY_BROKER_URL=app.config['REDIS_DATABASE_URI']
)
celery = make_celery(app)
celery.conf.beat_schedule = {
'schedule-refresh-channels': {
'task': 'push_notification.refresh',
'schedule': crontab(minute=0, hour=0, day_of_week='sunday'),
},
'schedule-create-channels': {
'task': 'push_notification.add-channels',
'schedule': crontab(minute=0, hour=0, day_of_week='sunday'),
},
}
celery.conf.timezone = 'UTC'