Skip to content

Commit

Permalink
Handle cases where workflow job is skipped or cancelled (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet authored Apr 15, 2024
1 parent 42540d9 commit c0fa117
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion runner_manager/models/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def find_from_webhook(cls, webhook: WorkflowJobEvent) -> "Runner | None":
Returns:
Runner: A runner object
"""

if webhook.workflow_job.runner_id is None:
return None
try:
runner: Runner | None = cls.find(
cls.id == webhook.workflow_job.runner_id
Expand Down
4 changes: 3 additions & 1 deletion runner_manager/models/runner_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def save(
return super().save(pipeline=pipeline)

@classmethod
def find_from_webhook(cls, webhook: WorkflowJobEvent) -> "RunnerGroup":
def find_from_webhook(cls, webhook: WorkflowJobEvent) -> "RunnerGroup | None":
"""Find the runner group from a webhook instance.
Args:
Expand All @@ -280,6 +280,8 @@ def find_from_webhook(cls, webhook: WorkflowJobEvent) -> "RunnerGroup":
Returns:
RunnerGroup: Runner group instance.
"""
if webhook.workflow_job.runner_group_id is None:
return None
try:
group: RunnerGroup | None = cls.find(
(cls.id == webhook.workflow_job.runner_group_id)
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/models/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def test_find_from_webhook(runner: Runner, webhook: WorkflowJobCompleted):
assert Runner.find_from_webhook(webhook) == runner
runner.delete(runner.pk)
assert Runner.find_from_webhook(webhook) is None
webhook.workflow_job.runner_id = None
assert Runner.find_from_webhook(webhook) is None


def test_update_from_github(runner: Runner, github: GitHub):
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/models/test_runner_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def test_find_from_webhook(runner_group: RunnerGroup, webhook: WorkflowJobComple
assert RunnerGroup.find_from_webhook(webhook) == runner_group
runner_group.delete(runner_group.pk)
assert RunnerGroup.find_from_webhook(webhook) is None
webhook.workflow_job.runner_group_name = None
webhook.workflow_job.runner_group_id = None
assert RunnerGroup.find_from_webhook(webhook) is None


def test_runner_group_delete_method(runner_group: RunnerGroup, github: GitHub):
Expand Down

0 comments on commit c0fa117

Please sign in to comment.