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

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'

4

1 に答える 1