我有一个应用程序,使用芹菜执行异步任务,使用redis作为其代理和结果后端,并将redis设置为使用unix套接字。这是我的芹菜和经纪人的网址
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连接设置超时?
这个问题似乎与系统上安装的redis服务器版本有关,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//'
我希望这个答案能满足你的所有需求。干杯
在Celery:中,几个库中存在导致此异常的错误
- https://github.com/celery/celery/issues/2903
- https://github.com/celery/kombu/pull/590
如果您使用带有UNIX套接字的Redis作为代理,那么还没有简单的解决方法。除非您对celery
、kombu
和/或redis-py
库进行猴子补丁。。。
目前,我建议您使用带有TCP连接的Redis,或者切换到另一个代理,例如RabbitMQ。