5

我正在尝试配置 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

我的任务.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'

4

1 回答 1

1

这是 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.

于 2018-02-19T10:34:21.653 回答