8000 added a new event 'progress' by honnix · Pull Request #2498 · spotify/luigi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

added a new event 'progress' #2498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion < 8000 span class="Truncate"> luigi/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

''' Definitions needed for events. See :ref:`Events` for info on how to use it.'''
""" Definitions needed for events. See :ref:`Events` for info on how to use it."""


class Event(object):
Expand All @@ -25,6 +25,10 @@ class Event(object):
DEPENDENCY_PRESENT = "event.core.dependency.present"
BROKEN_TASK = "event.core.task.broken"
START = "event.core.start"
#: This event can be fired by the task itself while running. The purpose is
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried following existing inline doc. How does it look? @Tarrasch

#: for the task to report progress, metadata or any generic info so that
#: event handler listening for this can keep track of the progress of running task.
PROGRESS = "event.core.progress"
FAILURE = "event.core.failure"
SUCCESS = "event.core.success"
PROCESSING_TIME = "event.core.processing_time"
Expand Down
18 changes: 15 additions & 3 deletions test/event_callbacks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class EmptyTask(Task):
fail = luigi.BoolParameter()

def run(self):
self.trigger_event(Event.PROGRESS, self, {"foo": "bar"})
if self.fail:
raise DummyException()

Expand Down Expand Up @@ -67,6 +68,8 @@ def save_task(task):
self.assertEqual(saved_tasks, [t])

def _run_empty_task(self, fail):
progresses = []
progresses_data = []
successes = []
failures = []
exceptions = []
Expand All @@ -80,18 +83,27 @@ def failure(task, exception):
failures.append(task)
exceptions.append(exception)

@EmptyTask.event_handler(Event.PROGRESS)
def progress(task, data):
progresses.append(task)
progresses_data.append(data)

t = EmptyTask(fail)
build([t], local_scheduler=True)
return t, successes, failures, exceptions
return t, progresses, progresses_data, successes, failures, exceptions

def test_success(self):
t, successes, failures, exceptions = self._run_empty_task(False)
t, progresses, progresses_data, successes, failures, exceptions = self._run_empty_task(False)
self.assertEqual(progresses, [t])
self.assertEqual(progresses_data, [{"foo": "bar"}])
self.assertEqual(successes, [t])
self.assertEqual(failures, [])
self.assertEqual(exceptions, [])

def test_failure(self):
t, successes, failures, exceptions = self._run_empty_task(True)
t, progresses, progresses_data, successes, failures, exceptions = self._run_empty_task(True)
self.assertEqual(progresses, [t])
self.assertEqual(progresses_data, [{"foo": "bar"}])
self.assertEqual(successes, [])
self.assertEqual(failures, [t])
self.assertEqual(len(exceptions), 1)
Expand Down
0