Skip to content

Cancel running jobs by event rather than previous commit SHA#3076

Open
nforro wants to merge 2 commits intopackit:mainfrom
nforro:canceling
Open

Cancel running jobs by event rather than previous commit SHA#3076
nforro wants to merge 2 commits intopackit:mainfrom
nforro:canceling

Conversation

@nforro
Copy link
Copy Markdown
Member

@nforro nforro commented Mar 24, 2026

Some triggers such as comment commands have no relation to a commit SHA, so canceling doesn't work for them. We can use project event instead to identify running jobs that should be canceled, but event IDs are reused and we need to exclude current jobs, i.e. those that have been started by our trigger. To make that possible, before starting any tasks for a job record datetime of the most recent pipeline of the triggering event and use that as a cutoff time when filtering running jobs to cancel.

TODO:

  • Write new tests or update the old ones to cover new functionality.

Related to #3005.

RELEASE NOTES BEGIN

Packit now cancels running jobs even after manual retriggering.

RELEASE NOTES END

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a cancel_cutoff_time mechanism to prevent accidental cancellation of newly triggered jobs within the same event batch. This involves adding cancel_cutoff_time to Event and EventData classes, and modifying get_running methods across various build and test models (Copr, Koji, Testing Farm, Log Detective) to filter jobs based on this new timestamp and project_event_type/event_id instead of commit_sha. A new get_latest_datetime_for_event method was added to PipelineModel to determine this cutoff time. Review comments highlight the need for robust checks to ensure cancel_cutoff_time and db_project_event are not None to prevent unintended job cancellations and to improve docstring clarity for the created_before parameter in get_running methods.

@centosinfra-prod-github-app
Copy link
Copy Markdown
Contributor

@nforro
Copy link
Copy Markdown
Member Author

nforro commented Mar 24, 2026

/gemini review

@centosinfra-prod-github-app
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the job cancellation logic to use event-based filtering with a cancel_cutoff_time instead of relying solely on commit_sha. This change introduces a cancel_cutoff_time field to Event and EventData classes, which is then used to query running Copr builds, Koji builds, Testing Farm runs, and Log Detective runs. A new PipelineModel.get_latest_datetime_for_event method is added to retrieve the most recent pipeline datetime for a given project event, which helps determine the cancel_cutoff_time. This ensures that only jobs related to a specific event and initiated before a certain time are considered for cancellation, preventing unintended cancellations of unrelated jobs. Numerous tests have been updated to reflect these changes, including mocking the new cancel_cutoff_time and event-based parameters, and new tests have been added to verify the correctness of the new cancellation logic.

@nforro nforro moved this from New to In review in Packit pull requests Mar 24, 2026
@centosinfra-prod-github-app
Copy link
Copy Markdown
Contributor

nforro added 2 commits March 31, 2026 16:52
Some triggers such as comment commands have no relation to a commit SHA,
so canceling doesn't work for them. We can use project event instead to
identify running jobs that should be canceled, but event IDs are reused
and we need to exclude current jobs, i.e. those that have been started
by our trigger. To make that possible, before starting any tasks
for a job record datetime of the most recent pipeline
of the triggering event and use that as a cutoff time when filtering
running jobs to cancel.

Signed-off-by: Nikola Forró <nforro@redhat.com>
Signed-off-by: Nikola Forró <nforro@redhat.com>
Assisted-by: Claude Opus 4.6 via Claude Code
@centosinfra-prod-github-app
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Member

@m-blaha m-blaha left a comment

Choose a reason for hiding this comment

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

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants