[关闭]
@tony-yin 2018-04-03T01:23:46.000000Z 字数 572 阅读 1068

Celery Demo

Celery


rabbitmq

yum install erlang

yum install rabbitmq-server -y
systemctl start rabbitmq-server
systemctl enable rabbitmq-server

redis

yum repolist
yum install redis php-pecl-redis
systemctl start redis
systemctl enable redis
pip install redis

client.py

  1. from tasks import add
  2. add.delay(5, 5)
  3. with open('output.log', 'a') as f:
  4. f.write('===== current ====' + "\n")

tasks.py

  1. from celery import Celery
  2. app = Celery('tasks', broker='redis://guest@localhost//')
  3. @app.task
  4. def add(x, y):
  5. with open('output.log', 'a') as f:
  6. f.write('===== delay ====' + "\n")
  7. return x + y

Command

server:

  1. celery -A tasks worker --loglevel=info

client:

  1. python client.py
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注