Skip to content

Commit

Permalink
fix assertion error due to incorrect type assumption in webhook times…
Browse files Browse the repository at this point in the history
…tamp (#564)

Following #555, an assertion error was occuring due to the assumption
that both the `created_at` and `started_at` fields in the `workflow_job`
webhooks were `datetime` instead of `str`. This, following the pattern
in #555, converts the `str` value of the webhook into `datetime` before
the assertion.
  • Loading branch information
tcarmet authored Apr 2, 2024
2 parents 0947ee4 + e00cd13 commit 87e8ea2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions runner_manager/jobs/workflow_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,20 @@ def log_workflow_job(webhook: WorkflowJobEvent) -> None:
def time_to_start(webhook: WorkflowJobEvent) -> timedelta:
"""From a given webhook, calculate the time it took to start the job"""

assert isinstance(webhook.workflow_job.started_at, datetime)
assert isinstance(webhook.workflow_job.created_at, datetime)
return webhook.workflow_job.started_at - webhook.workflow_job.created_at
if isinstance(webhook.workflow_job.created_at, str):
created_at = datetime.fromisoformat(webhook.workflow_job.created_at)
else:
created_at = webhook.workflow_job.created_at

if isinstance(webhook.workflow_job.started_at, str):
started_at = datetime.fromisoformat(webhook.workflow_job.started_at)
else:
started_at = webhook.workflow_job.started_at

assert isinstance(started_at, datetime)
assert isinstance(created_at, datetime)

return started_at - created_at


def completed(webhook: WorkflowJobCompleted) -> int:
Expand Down

0 comments on commit 87e8ea2

Please sign in to comment.