我有以下项目:https ://github.com/gonvaled/celery-test
我想要一些仅在工作人员中执行的代码,但我不知道该怎么做。
这是正在运行的工人:
pegasus $ celery worker --app=proj
This should only be executed in the worker
-------------- celery@pegasus v3.0.9 (Chiastic Slide)
---- **** -----
--- * *** * -- [Configuration]
-- * - **** --- . broker: amqp://guest@localhost:5672//
- ** ---------- . app: tasks:0x98d188c
- ** ---------- . concurrency: 2 (processes)
- ** ---------- . events: OFF (enable -E to monitor this worker)
- ** ----------
- *** --- * --- [Queues]
-- ******* ---- . celery: exchange:celery(direct) binding:celery
--- ***** -----
[2012-12-22 17:50:31,868: WARNING/MainProcess] celery@pegasus has started.
这是正在运行的客户端:
$ python client.py
This should only be executed in the worker
8
客户端不应打印This should only be executed in the worker
。显然,我需要以某种方式保护那部分代码,但我不知道如何。如何确保某些代码仅在工作人员中运行?