我正在使用Django-celery和Redis后端推送芹菜队列中的任务。我正在队列中使用相同的自定义task_id推送任务。文档说task_id是UUID,它应该是唯一的。但我能够在队列中添加多个具有相同task_id的任务。如果队列中已存在具有相同task_id的任务,则应该引发异常。
@task
def register_task(a, b):
print a + b
@task
def deregister_task(a, b, c):
print a + b + c
taskid=str(UUID(md5('test').hexdigest()))
register_task.apply_async(args=('hello', 'world'), task_id=taskid, countdown=60)
deregister_task.apply_async(args=('sample', 'hello', 'world'), task_id=taskid, countdown=60)
i = inspect()
i.scheduled()
{u'celery@Suyashs-MacBook-Pro.local': [{u'eta': u'2017-06-05T17:15:33.947002',
u'priority': 6,
u'request': {u'acknowledged': False,
u'args': u"('sample', 'hello', 'world')",
u'delivery_info': {u'exchange': u'celery',
u'priority': 0,
u'redelivered': None,
u'routing_key': u'celery'},
u'hostname': u'celery@Suyashs-MacBook-Pro.local',
u'id': u'098f6bcd-4621-d373-cade-4e832627b4f6',
u'kwargs': u'{}',
u'name': u'flight.tasks.deregister_task',
u'time_start': None,
u'worker_pid': None}},
{u'eta': u'2017-06-05T17:15:44.234537',
u'priority': 6,
u'request': {u'acknowledged': False,
u'args': u"('hello', 'world')",
u'delivery_info': {u'exchange': u'celery',
u'priority': 0,
u'redelivered': None,
u'routing_key': u'celery'},
u'hostname': u'celery@Suyashs-MacBook-Pro.local',
u'id': u'098f6bcd-4621-d373-cade-4e832627b4f6',
u'kwargs': u'{}',
u'name': u'flight.tasks.register_task',
u'time_start': None,
u'worker_pid': None}}]}