-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
40 lines (31 loc) · 890 Bytes
/
tasks.py
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
from celery.schedules import crontab
from app import celery
@celery.task(bind=True, name='remind_appointment')
def remind_appointment(args):
'''
Get data from your database model such as
User.query.all() and perform some operation
'''
pass
@celery.task(bind=True, name='send_email')
def send_email(args):
'''
Get data from your database model such as
User.query.all() and perform some operation to
send marketing campaigns
'''
pass
# start celery worker
# celery -A tasks worker --loglevel=info
# start celery beat
# celery -A tasks.celery beat --loglevel=info
celery.conf.beat_schedule = {
'appointment reminder in every 2 minutes': {
'task': 'remind_appointment',
'schedule': 120.0
},
'send email every 2 hours': {
'task': 'send_email',
'schedule': crontab(hour='*/2')
}
}