Search code examples
pythonshellluigi

How to override luigi complete() method so that the underlying task will come to know the previous ones were completed?


I have the following tasks :

class TaskA(ExternalProgramTask):
    def program_args(self):
        return ["/simpleScripts/shell5.bash"]
    def program_environment(self):
        env = os.environ.copy()
        return env

The shell script is running properly. After this if I try to run any other task , those task will fail by throwing "unfulfilled dependency error" in TaskA.

The reason I understood is usually Luigi will have output() method where a localTarget is created and thus Luigi will come to know that that Task is completed.

Here while running shell script I don't have any localTarget and thus luigi fails to understand whether it is completed or not. How to make this correct ?


Solution

  • Override the complete method of Luigi and return true if all the desired operations are completed

    class TaskA(luigi.Task):
        data_text = luigi.Parameter()
    
        def complete(self):
            print("The task is complete")
            print("The data text", self.data_text)
            return True
    
    

    luigi --module [File_Name] TaskA --data-text "Welcome" --local-scheduler