我在运行Ubuntu 16.04,Gunicorn,Nginx的Digital Ocean上运行Django 1.11(使用Cookiecutter-Django模板构建)服务器,并且正在尝试使用Redis设置Celery任务。当我这样做时,该服务似乎可以正常工作并接收定期任务:
celery -A config worker -B -l debug
接收并接受任务,但它们不会执行。为了测试,我发送了这个功能:
@shared_task(name="sum_two_numbers")
def add(x, y, **kwargs):
return x + y
使用:
add.delay(1,3)
这是Celery运行的控制台的完整打印输出:
-------------- celery@myproject v4.1.0 (latentcall)
---- **** -----
--- * *** * -- Linux-4.4.0-112-generic-x86_64-with-Ubuntu-16.04-xenial 2018-02-19 23:18:12
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: myproject:0x7f2cd60dc9e8
- ** ---------- .> transport: redis://127.0.0.1:6379//
- ** ---------- .> results: redis://localhost:6379/
- *** --- * --- .> concurrency: 1 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
[tasks]
. . .
. sum_two_numbers
[2018-02-19 23:18:12,858: INFO/MainProcess] Connected to redis://127.0.0.1:6379//
[2018-02-19 23:18:12,876: INFO/MainProcess] mingle: searching for neighbors
[2018-02-19 23:18:13,910: INFO/MainProcess] mingle: all alone
[2018-02-19 23:18:13,924: WARNING/MainProcess] /home/user/.virtualenvs/myproject/lib/python3.5/site-packages/celery/fixups/django.py:202: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments!
warnings.warn('Using settings.DEBUG leads to a memory leak, never '
[2018-02-19 23:19:38,714: INFO/MainProcess] Received task: sum_two_numbers[ab5b5547-1337-4dec-8848-c15e1a194b51]
[2018-02-19 23:19:38,715: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x7f2cd5fce510> (args:('sum_two_numbers', 'ab5b5547-1337-4dec-8848-c15e1a194b51', {'root_id': 'ab5b5547-1337-4dec-8848-c15e1a194b51', 'task': 'sum_two_numbers', 'group': None, 'correlation_id': 'ab5b5547-1337-4dec-8848-c15e1a194b51', 'id': 'ab5b5547-1337-4dec-8848-c15e1a194b51', 'timelimit': [None, None], 'expires': None, 'retries': 0, 'argsrepr': '(1, 3)', 'eta': None, 'origin': 'gen23535@myproject', 'reply_to': 'e67c54ef-3c66-3720-9e1f-62ef3d76882d', 'kwargsrepr': '{}', 'lang': 'py', 'parent_id': None, 'delivery_info': {'priority': 0, 'redelivered': None, 'routing_key': 'celery', 'exchange': ''}}, b'[[1, 3], {}, {"errbacks": null, "chain": null, "chord": null, "callbacks": null}]', 'application/json', 'utf-8') kwargs:{})
[2018-02-19 23:19:38,722: DEBUG/MainProcess] Task accepted: sum_two_numbers[ab5b5547-1337-4dec-8848-c15e1a194b51] pid:23512
当我在本地运行时,它运行得很好。我在这里做错了什么?
答案 0 :(得分:0)
您可以尝试使用此命令-
celery -A <App_name> worker -l info --without-gossip --without-mingle --without-heartbeat -Ofair --pool=solo
这通过合并独奏情绪解决了m个问题。也许这也是您的情况。