Python-Celery frame using

Two, Celery basic use 

1. Create a celery application used to define your task list, create a file called tasks.py task bar.

Celery celery Import from 

# configured celery and the backend Broker 
App = Celery ( 'Task1', backend = 'Redis: //127.0.0.1: 6379/0', Broker = 'Redis: //127.0.0.1: 6379/0 ') 
 
# Task ordinary function decorated Celery 
@ app.task   
DEF FUNC (X, Y): 
    return X + Y

So come, we just defined the function func function and task worker (celery objects). worker equivalent workers.

2. Start Celery Worker to start listening and perform tasks. We have a broker, backend we have, task we have, it is time to run a worker to work, run under the directory tasks.py:

[root @ localhost ~] # celery -A tasks worker --loglevel = info # starting method. 1 
[the root @ localhost ~] # Celery -A Tasks worker --l Debug starting method # 2

  

Guess you like

Origin www.cnblogs.com/liuhaidon/p/12036498.html