-
Notifications
You must be signed in to change notification settings - Fork 1
/
vege4.py
43 lines (28 loc) · 979 Bytes
/
vege4.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
41
42
43
from __future__ import absolute_import
from celery import Celery
from celery import group, chain, chord, chunks
app = Celery('work-flow') # 建立一個Celery的instance
# celery的相關參數設定
class Config:
broker_url = 'amqp://celeryman:pass1234@localhost:5672/celery_vhost'
result_backend = 'redis://localhost:6379/'
timezone = 'Asia/Taipei'
app.config_from_object(Config) # 載入設定
# 在實例中加入task
@app.task(name='hello')
def hello(name='world'):
return f'hello {name}'
@app.task(name='add')
def add(x, y):
return x + y
# add periodic task
@app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
sender.add_periodic_task(5.0,
hello.s('there'),
name='every 5s hello')
sender.add_periodic_task(5.0,
add.s(5, 5),
name='every 5s add')
if __name__ == '__main__':
app.start()