Skip to content

Commit

Permalink
add task_id parameter to TaskTimedOutError and TaskFailedError
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Schlossarek committed Jan 14, 2021
1 parent f207095 commit 6883c47
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions nailgun/entity_mixins.py
Expand Up @@ -48,10 +48,18 @@
class TaskTimedOutError(Exception):
"""Indicates that a task did not finish before the timout limit."""

def __init__(self, message, task_id):
super().__init__(message)
self.task_id = task_id


class TaskFailedError(Exception):
"""Indicates that a task finished with a result other than "success"."""

def __init__(self, message, task_id):
super().__init__(message)
self.task_id = task_id


def _poll_task(task_id, server_config, poll_rate=None, timeout=None):
"""Implement :meth:`nailgun.entities.ForemanTask.poll`.
Expand Down Expand Up @@ -94,13 +102,17 @@ def raise_task_timeout(): # pragma: no cover
except KeyboardInterrupt: # pragma: no cover
# raise_task_timeout will raise a KeyboardInterrupt when the timeout
# expires. Catch the exception and raise TaskTimedOutError
raise TaskTimedOutError(f'Timed out polling task {task_id}. Task information: {task_info}')
raise TaskTimedOutError(
f"Timed out polling task {task_id}. Task information: {task_info}", task_id
)
finally:
timer.cancel()

# Check for task success or failure.
if task_info['result'] != 'success':
raise TaskFailedError(f'Task {task_id} did not succeed. Task information: {task_info}')
raise TaskFailedError(
f"Task {task_id} did not succeed. Task information: {task_info}", task_id
)
return task_info


Expand Down

0 comments on commit 6883c47

Please sign in to comment.