Skip to content

A small instant demostrated how celery works

source edited this page Sep 22, 2016 · 7 revisions

package

get lastest package via https://github.com/sourceonly/program/tree/gh-pages/program/python/celery

celery server

To start celery as worker

export PYTHONPATH=<path-to-our-myapp-location>
celery -A myapp worker -l info

or one might want to add queue to specifical worker

<do PYTHONPATH here>
celery -A myapp worker -l info -Q machine1

then you can monitor the output of the work via console

celery test

  • we predefined a series of function with can easily be tested
# first you still need to make your myworkapp and your celery_test.py under your PYTHONPATH
# we can enter interactive mode of python console
python  
>> from myapp.agent import add
>> res=add.delay(4,5)
  • another example is that we can use predefined runprocess command to invoke system command
python
>> from myapp.agent import runprocess
>> res=runprocess.apply_async(args=['dir','/home/test/a.out','/home/test/e.out'],queue='machine1',routing_key='machine1')

or function call as what is in sh file or bat file as command line

Clone this wiki locally