Add celery usage more

pull/530/head
ibuler 2016-08-31 16:48:12 +08:00
parent dd80b94b43
commit 5350f83275
3 changed files with 14 additions and 2 deletions

View File

@ -22,6 +22,7 @@ from __future__ import absolute_import
import time
from celery import shared_task
from common import celery_app
@shared_task
@ -31,6 +32,12 @@ def longtime_add(x, y):
time.sleep(5)
print 'long time task finished'
return x + y
@celery_app.task(name='hello-world')
def hello():
print 'hello world!'
```
#### Run celery in development

View File

@ -17,6 +17,5 @@ app = Celery('jumpserver')
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
print(settings.BROKER_URL)
app.autodiscover_tasks(lambda: [app_config.split('.')[0] for app_config in settings.INSTALLED_APPS])

View File

@ -2,6 +2,7 @@ from __future__ import absolute_import
import time
from celery import shared_task
from common import celery_app
@shared_task
@ -10,4 +11,9 @@ def longtime_add(x, y):
# sleep 5 seconds
time.sleep(5)
print 'long time task finished'
return x + y
return x + y
@celery_app.task(name='hello-world')
def hello():
print('hello world!')