gpt4 book ai didi

python - 如何正确配置 Luigi 任务重试?

转载 作者:行者123 更新时间:2023-11-28 19:11:00 26 4
gpt4 key购买 nike

我正在尝试配置 Luigi 的重试机制,以便重试失败的任务几次。然而,当任务重试成功时,Luigi 退出失败:

===== Luigi Execution Summary =====

Scheduled 3 tasks of which:
* 2 ran successfully:
- 1 FailOnceThenSucceed(path=/tmp/job-id-18.subtask)
- 1 MasterTask(path=/tmp/job-id-18)
* 1 failed:
- 1 FailOnceThenSucceed(path=/tmp/job-id-18.subtask)

This progress looks :( because there were failed tasks

所以问题是:如何配置 Luigi(我已经使用 pip install 安装了 2.3.3 版),以便当任务失败一次,但随后重试成功时,Luigi 将成功退出并显示 This进度看起来 :) 而不是失败 这个进度看起来 :(?

这是我提出的最小调度程序和工作程序配置,以及用于演示行为的任务:

[scheduler]
retry_count = 3
retry-delay = 1

[worker]
keep_alive=true

我的任务.py:

import luigi


class FailOnceThenSucceed(luigi.Task):
path = luigi.Parameter()

def output(self):
return luigi.LocalTarget(self.path)

def run(self):
failmarker = luigi.LocalTarget(self.path + ".hasfailedonce")
if failmarker.exists():
with self.output().open('w') as target:
target.write('OK')
else:
with failmarker.open('w') as marker:
marker.write('Failed')
raise RuntimeError("Failed once")


class MasterTask(luigi.Task):
path = luigi.Parameter()

def requires(self):
return FailOnceThenSucceed(path=self.path + '.subtask')

def output(self):
return luigi.LocalTarget(self.path)

def run(self):
with self.output().open('w') as target:
target.write('OK')

执行示例:

PYTHONPATH=. luigi --module mytasks MasterTask --workers=2 --path='/tmp/job-id-18'

最佳答案

这是 Luigi 的一个老问题 - 成功重试的任务在失败时没有被标记为这样,然后在重试时成功: https://github.com/spotify/luigi/issues/1932

它在版本 2.7.2 中得到修复: https://github.com/spotify/luigi/releases/tag/2.7.2

我建议您升级到最新的 Luigi 版本,即通过运行 pip install -U luigi

关于python - 如何正确配置 Luigi 任务重试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40218393/

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