mirror of https://github.com/jumpserver/jumpserver
Add celery usage more
parent
dd80b94b43
commit
5350f83275
|
@ -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):
|
||||||
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')
|
||||||
# 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
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
|
from common import celery_app
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
|
@ -10,4 +11,9 @@ def longtime_add(x, y):
|
||||||
# sleep 5 seconds
|
# sleep 5 seconds
|
||||||
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!')
|
||||||
|
|
Loading…
Reference in New Issue