Commit 5350f832 authored by ibuler's avatar ibuler

Add celery usage more

parent dd80b94b
...@@ -22,6 +22,7 @@ from __future__ import absolute_import ...@@ -22,6 +22,7 @@ from __future__ import absolute_import
import time import time
from celery import shared_task from celery import shared_task
from common import celery_app
@shared_task @shared_task
...@@ -31,6 +32,12 @@ def longtime_add(x, y): ...@@ -31,6 +32,12 @@ def longtime_add(x, y):
time.sleep(5) time.sleep(5)
print 'long time task finished' print 'long time task finished'
return x + y return x + y
@celery_app.task(name='hello-world')
def hello():
print 'hello world!'
``` ```
#### Run celery in development #### Run celery in development
......
...@@ -17,6 +17,5 @@ app = Celery('jumpserver') ...@@ -17,6 +17,5 @@ app = Celery('jumpserver')
# pickle the object when using Windows. # pickle the object when using Windows.
app.config_from_object('django.conf:settings') 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]) app.autodiscover_tasks(lambda: [app_config.split('.')[0] for app_config in settings.INSTALLED_APPS])
...@@ -2,6 +2,7 @@ from __future__ import absolute_import ...@@ -2,6 +2,7 @@ from __future__ import absolute_import
import time import time
from celery import shared_task from celery import shared_task
from common import celery_app
@shared_task @shared_task
...@@ -11,3 +12,8 @@ def longtime_add(x, y): ...@@ -11,3 +12,8 @@ def longtime_add(x, y):
time.sleep(5) time.sleep(5)
print 'long time task finished' print 'long time task finished'
return x + y 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