我有一个使用celery for async-task的应用程序,我使用redis作为其代理和结果后端,我设置redis使用unix socket。 这是我对芹菜和经纪人的网址
brok = 'redis+socket://:ABc@/tmp/redis.sock'
app = Celery('NTWBT', backend=brok, broker=brok)
app.conf.update(
BROKER_URL=brok,
BROKER_TRANSPORT_OPTIONS={
"visibility_timeout": 3600
},
CELERY_RESULT_BACKEND=brok,
CELERY_ACCEPT_CONTENT=['pickle', 'json', 'msgpack', 'yaml'],
)
但每次我添加一份工作芹菜都会给我这个错误
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 283, in trace_task
uuid, retval, SUCCESS, request=task_request,
File "/usr/local/lib/python2.7/dist-packages/celery/backends/base.py", line 257, in store_result
request=request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/backends/base.py", line 491, in _store_result
self.set(self.get_key_for_task(task_id), self.encode(meta))
File "/usr/local/lib/python2.7/dist-packages/celery/backends/redis.py", line 160, in set
return self.ensure(self._set, (key, value), **retry_policy)
File "/usr/local/lib/python2.7/dist-packages/celery/backends/redis.py", line 149, in ensure
**retry_policy
File "/usr/local/lib/python2.7/dist-packages/kombu/utils/__init__.py", line 246, in retry_over_time
return fun(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/backends/redis.py", line 169, in _set
pipe.execute()
File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 2620, in execute
self.shard_hint)
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 897, in get_connection
connection = self.make_connection()
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 906, in make_connection
return self.connection_class(**self.connection_kwargs)
TypeError: __init__() got an unexpected keyword argument 'socket_connect_timeout'
我应该使用哪个选项让芹菜为其redis连接设置超时?
答案 0 :(得分:0)
似乎这个问题与系统上安装的redis-server版本有关,socket_connect_timeout最初是在redis 2.10.0中引入的。
因此您需要更新您的redis版本。
如果你在ubuntu服务器上运行,你可以安装官方的apt存储库:
$ sudo apt-get install -y python-software-properties
$ sudo add-apt-repository -y ppa:rwky/redis
$ sudo apt-get update
$ sudo apt-get install -y redis-server
并更新到芹菜的最新版本。
这是芹菜中的github问题,因为不仅你遇到了这个问题:https://github.com/celery/celery/issues/2903
如果一切都不适合你,我建议使用rabbitmq而不是Redis:
$ sudo apt-get install rabbitmq-server
$ sudo pip install librabbitmq
并在您的应用中使用此CELERY_BROKER_URL配置芹菜:
'amqp://guest:guest@localhost:5672//'
我希望这个答案能满足您的所有需求。 干杯
答案 1 :(得分:0)
在Celery中,有几个库中存在导致此异常的错误:
如果您使用带有UNIX套接字的Redis作为代理,那么还没有简单的修复方法。除非你修补celery
,kombu
和/或redis-py
个库......
目前,我建议您使用Redis与TCP连接,或切换到另一个代理,例如的RabbitMQ。