Skip to content
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

Handle cases where workflow job is skipped or cancelled #579

Merged
merged 2 commits into from
Apr 15, 2024
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
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
Loading