gpt4 book ai didi

python - Celery + Redis 问题

转载 作者:可可西里 更新时间:2023-11-01 11:48:34 25 4
gpt4 key购买 nike

在我设置 CELERY_ALWAYS_EAGER = False 之前,我有一个在 celery 中按预期工作的应用程序。

# main file
jobs = get_report_jobs_from_db()

for job in jobs:
out = run_job.delay(job)

status, id = out.state, out.task_id
# Should be status string and UUID.
save_job(job, status, id) # record to db
# On bad calls status == id and is a UUID.



# celery file
from foo import do_something, write_id_back

@celery.task
def run_job(job):
id = do_something(job) # do_something returns a report_id
write_id_back(job, id) # write that id back to the originating job record

#foo file

def do_something(job):
prep_data = prep_job(job)
report_id = mysql_insert(job, prep_data)
# A report_id is returned if the insert suceeds otherwise it is
# null. The INSERT always works if I run
# CELERY_ALWAYS_EAGER = True, but if redis is involved it fails
# routinely
return report_id

如果我在 CELERY_ALWAYS_EAGER = True 下运行我的代码,绕过 redis,我会将所有 report_id 重新附加到我的原始作业。这就是我想要的。

但是,一旦我设置了 CELERY_ALWAYS_EAGER = False,除了 3 之外,我的所有 report_id 都写回了,而且它们总是相同的。这三种工作在重要方面相似,这使它们有别于其他工作。

现在,这是我不明白的。如果我打乱作业列表(即 random.shuffle(jobs)),我会得到 6-8 次失败的 id 写入。它会有所不同。

谁能告诉我这里可能发生了什么?

此外,当我尝试检查失败作业的 task_id 的状态而不是获取状态字符串(例如“PENDING”、“SUCCESS”)时,我得到了 task_id 哈希值。

知道如何调试这个问题,或者它可能是什么吗?

最佳答案

问题是有多个 celery 实例在运行。

如果您遇到违反常规调查的奇怪 celery 问题,请务必检查您的 celery 进程:

ps -ef | grep celery

确保您认识所有这些。在我的例子中,有一个旧的 celery 进程用完了我忘记的主管。它只会在某些情况下进行干预,并且会在对某些神秘位置进行记录时吞下我的记录尝试。

关于python - Celery + Redis 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32535914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com