如何正确配置 Luigi 任务重试?
How to configure Luigi task retry correctly?
我正在尝试配置 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 progress looks :)
而不是失败 This progress looks :(
?
这是我提出的最小调度程序和工作程序配置,以及演示行为的任务:
[scheduler]
retry_count = 3
retry-delay = 1
[worker]
keep_alive=true
mytasks.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
。
我正在尝试配置 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 progress looks :)
而不是失败 This progress looks :(
?
这是我提出的最小调度程序和工作程序配置,以及演示行为的任务:
[scheduler]
retry_count = 3
retry-delay = 1
[worker]
keep_alive=true
mytasks.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
。