A brief introduction: Today's talk about asynchronous processing of one of the two functions of celery
Two standard processes:
1 build config file
class Config:
ENABLE_UTC = False
CELERY_RESULT_BACKEND = 'Redis: //127.0.0.1: 6379/5'
BROKER_URL = 'Redis: //127.0.0.1: 6379/6'
Note 1 All parameters must be capitalized, and is fixed value
2, and the queue result sets are employed herein redis, naming two different libraries on the line
2 to establish celery file
App = Celery ( 'test1')
app.config_from_object (Config)
app.autodiscover_tasks ([ 'celery_demo'])
. 3 establishment tasks file
@ app.task # decorators can also be used here @shared_task
: DEF a ()
return "the ok" returns the value
4 to start more than worker
1 here we note that the output is otherwise found to ensure that the task can not be called.
similar format .tasks. function
Level 2 command is executed with the project directory celery
celery -A celery_demo.celery worker info -P eventlet --loglevel = -f log.name
. 5 Called
Result = a.delay ()
. 1 delay function call delay
2 result.ready ( ) True False representatives on behalf of the task is completed unfinished
result.status
PENDING, indicating no execution
Mistake Solution
Error 1 Received unregistered task of type 'mysql_web.celery_demo.tasks.mail '.
Possible Cause
1 if the task has been registered, then fill @ app.task (name = 'Tip of the task name')
2 If the task is not registered, then it case occurred in the introduction of the absolute path of third-party packages, you can temporarily copy the file
Four summary
1 is more than a standard celery into the framework of the asynchronous call drf