Handle luigi task had failed dependencies

The goal is to catch an event when a Luigi task had failed dependencies and do some cleanup.

I have a boilerplate code where I raise an Exception when a tmp-file is being created. As a result of this we get the event 1 had failed dependencies. Having had on_failure function for ProcessData I expected that data.txt and data_tmp.txt have to be removed. But on_failure function is not triggered and the file data.txt remains in a folder. How can I handle the event had failed dependencies properly?

Code:

import luigi
import os
import subprocess

class GenerateData(luigi.Task):
    output_path = luigi.Parameter(default='data.txt')

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

    def run(self):
        with self.output().open('w') as f:
            for i in range(10):
                f.write("{}n".format(i))


class GenerateTmpData(luigi.Task):
    output_path = luigi.Parameter(default='data_tmp.txt')

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

    def run(self):
        raise BaseException("Simulated error in GenerateTmpData")
        with self.output().open('w') as f:
            for i in range(10):
                f.write("{}n".format(i))


class ProcessData(luigi.Task):
    input_path = luigi.Parameter(default='data.txt')
    input_tmp_path = luigi.Parameter(default='data_tmp.txt')
    output_path = luigi.Parameter(default='processed_data.txt')

    def requires(self):
        yield GenerateTmpData(output_path=self.input_tmp_path)
        yield GenerateData(output_path=self.input_path)

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

    def run(self):
        with self.input()[1].open('r') as infile, self.output().open('w') as outfile:
            for line in infile:
                number = int(line.strip())
                processed_number = number * 2
                outfile.write("{}n".format(processed_number))

    def on_failure(self, exception):
        for item in self.input():
            if os.path.exists(item.path):
                os.remove(item.path)
        super(ProcessData, self).on_failure(exception)


def run_luigi_task():
    command = (
        'python -m luigi '
        '--module test ProcessData --local-scheduler '
    )
    subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, executable='/bin/bash')

if __name__ == '__main__':
    run_luigi_task()
    

Run as:

python test.py

Output:

DEBUG: Checking if ProcessData(input_path=data.txt, input_tmp_path=data_tmp.txt, output_path=processed_data.txt) is complete
DEBUG: Checking if GenerateTmpData(output_path=data_tmp.txt) is complete
DEBUG: Checking if GenerateData(output_path=data.txt) is complete
INFO: Informed scheduler that task   ProcessData_data_txt_data_tmp_txt_processed_data_t_ec6640af99   has status   PENDING
INFO: Informed scheduler that task   GenerateData_data_txt_1287d398ef   has status   PENDING
INFO: Informed scheduler that task   GenerateTmpData_data_tmp_txt_941f24e4a7   has status   PENDING
INFO: Done scheduling tasks
INFO: Running Worker with 1 processes
DEBUG: Asking scheduler for work...
DEBUG: Pending tasks: 3
INFO: [pid 763] Worker Worker(salt=208102894, workers=1, host=8b0c89a2a184, username=root, pid=763) running   GenerateData(output_path=data.txt)
INFO: [pid 763] Worker Worker(salt=208102894, workers=1, host=8b0c89a2a184, username=root, pid=763) done      GenerateData(output_path=data.txt)
DEBUG: 1 running tasks, waiting for next task to finish
INFO: Informed scheduler that task   GenerateData_data_txt_1287d398ef   has status   DONE
DEBUG: Asking scheduler for work...
DEBUG: Pending tasks: 2
INFO: [pid 763] Worker Worker(salt=208102894, workers=1, host=8b0c89a2a184, username=root, pid=763) running   GenerateTmpData(output_path=data_tmp.txt)
ERROR: [pid 763] Worker Worker(salt=208102894, workers=1, host=8b0c89a2a184, username=root, pid=763) failed    GenerateTmpData(output_path=data_tmp.txt)
Traceback (most recent call last):
  File "/app/env/lib/python3.5/site-packages/luigi/worker.py", line 199, in run
    new_deps = self._run_get_new_deps()
  File "/app/env/lib/python3.5/site-packages/luigi/worker.py", line 141, in _run_get_new_deps
    task_gen = self.task.run()
  File "test.py", line 25, in run
    raise BaseException("Simulated error in GenerateTmpData")
BaseException: Simulated error in GenerateTmpData
DEBUG: 1 running tasks, waiting for next task to finish
INFO: Informed scheduler that task   GenerateTmpData_data_tmp_txt_941f24e4a7   has status   FAILED
DEBUG: Asking scheduler for work...
DEBUG: Done
DEBUG: There are no more tasks to run at this time
DEBUG: There are 2 pending tasks possibly being run by other workers
DEBUG: There are 2 pending tasks unique to this worker
DEBUG: There are 2 pending tasks last scheduled by this worker
INFO: Worker Worker(salt=208102894, workers=1, host=8b0c89a2a184, username=root, pid=763) was stopped. Shutting down Keep-Alive thread
INFO: 
===== Luigi Execution Summary =====

Scheduled 3 tasks of which:
* 1 ran successfully:
    - 1 GenerateData(output_path=data.txt)
* 1 failed:
    - 1 GenerateTmpData(output_path=data_tmp.txt)
* 1 were left pending, among these:
    * 1 had failed dependencies:
        - 1 ProcessData(input_path=data.txt, input_tmp_path=data_tmp.txt, output_path=processed_data.txt)

This progress looks :( because there were failed tasks

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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật