Hi There,
I'm new to Luigi, and I have a question:
When I decorate a class function with an event_handler, e.g.
@luigi.Task.event_handler(luigi.Event.SUCCESS)
it seems to fire for every Task, not just for the class that is decorated.
According to the
docs for event_handler, the event will be triggered only from that class or subclass, implying that it won't call the one above it.
I'm seeing that it's trigger for other classes. Here's an example (luex.py) I cobbled together of a ComplexTask, calling a SimpleTask, only the latter of which has an event_handler.
import luigi
class ComplexTask(luigi.Task):
""" This call the simple task before performing it's task"""
x = luigi.IntParameter()
y = luigi.IntParameter(default=32)
def requires(self):
return SimpleTask(self.x, self.y)
def run(self):
print self.x + self.y
class SimpleTask(luigi.Task):
x = luigi.IntParameter()
y = luigi.IntParameter(default=45)
def run(self):
print self.x * self.y
@luigi.Task.event_handler(luigi.Event.SUCCESS)
def celebrate_success(self):
"""
Report success event
Uses "-+--+--+--+--+--+--+--+--+--+-" as indicator
"""
print(26 * '-+-')
print("Yay!, {c} succeeded. :)".format(c=self.__class__.__name__))
print(26 * '-+-')
@luigi.Task.event_handler(luigi.Event.FAILURE)
def mourn_failure(self, exception):
"""
Report failure event
Uses "-!--!--!--!--!--!--!--!--!--!-" as indicator
"""
print(26 * '-!-')
print("Boo!, {c} failed. :(".format(c=self.__class__.__name__))
print(".. with this exception: '{e}'".format(e=str(exception)))
print(26 * '-!-')
def main():
""" This task can be run by: python <filename.py> <classname> <args>
For example:
python luex.py ComplexTask --x=10
"""
luigi.run()
if __name__ == "__main__":
main()
When I run this code I get output containing the following:
ERROR: [pid 5825] Worker Worker(salt=182110569, workers=1, host=luigi1, username=bill, pid=5825) failed ComplexTask(x=42, y=32)
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/luigi/worker.py", line 136, in run
raise RuntimeError('Unfulfilled %s at run time: %s' % (deps, ', '.join(missing)))
RuntimeError: Unfulfilled dependency at run time: SimpleTask(x=42, y=32)
-!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!-
Boo!, ComplexTask failed. :(
.. with this exception: 'Unfulfilled dependency at run time: SimpleTask(x=42, y=32)'
-!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!-
I'm not expecting to see this failure print out in this way.
It's seems that the ComplexTask failure is calling the SimpleTask's mourn_failure function, and that seems.. undesirable behavior.
Should I file a bug on github, or am I using this decorator incorrectly or differently than intended?
Cheers,
-Bill Tucker