簡體   English   中英

Celery + Redis 問題

[英]Celery + Redis Issue

我有一個在 celery 中按預期工作的應用程序,直到我設置 CELERY_ALWAYS_EAGER = False。

# 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_ids 重新附加到我的原始作業。 這就是我要的。

但是,一旦我設置了 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 進程用完了我已經忘記的主管。 它只會在某些情況下干擾,並且會在它干擾到某個神秘位置時吞下我的日志記錄嘗試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM