Commit 5350f832 authored by ibuler's avatar ibuler

Add celery usage more

parent dd80b94b
......@@ -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
......
......@@ -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])
......@@ -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
\ No newline at end of file
return x + y
@celery_app.task(name='hello-world')
def hello():
print('hello world!')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment