-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Implement auto-cancellation of concurrent jobs if the event is push #25716
Conversation
- Add a new function `CancelRunningJobs` to cancel all running jobs of a run - Update `FindRunOptions` struct to include `Ref` field and update its condition in `toConds` function - Implement auto cancellation of running jobs in the same workflow in `notify` function Signed-off-by: Bo-Yi Wu <[email protected]>
- Change the `Status` field in `CancelRunningJobs`, `FindRunOptions`, and `List` functions from a single `Status` to a slice of `Status`. - Update the condition in `toConds` function to check the length of `Status` slice instead of comparing a single `Status` value with `StatusUnknown`. - Modify the condition to use `builder.In` for matching multiple `Status` values instead of `builder.Eq` for a single `Status` value. Signed-off-by: Bo-Yi Wu <[email protected]>
services/actions/notifier_helper.go
Outdated
@@ -232,6 +232,12 @@ func notify(ctx context.Context, input *notifyInput) error { | |||
log.Error("jobparser.Parse: %v", err) | |||
continue | |||
} | |||
|
|||
// auto cancel running jobs in the same workflow | |||
if err := actions_model.CancelRunningJobs(ctx, run); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it will cancel the previous jobs of the same ref by default, I'm OK with this, and we can provide an options later if someone ask for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wolfogre Yes, move to another NEW PR.
- Add an index to the `Ref` field in the `ActionRun` struct - Modify the `CancelRunningJobs` function to use `total` instead of `len(runs)` for checking if there are no runs. Signed-off-by: Bo-Yi Wu <[email protected]>
- Remove the code that sets the status of a run to cancelled and updates the run in `CancelRunningJobs` function. Signed-off-by: Bo-Yi Wu <[email protected]>
Done |
Co-authored-by: Jason Song <[email protected]>
Please check #25716 (comment) |
…ame` - Add `WorkflowID` to the `CancelRunningJobs` function in `run.go` - Replace `WorkflowFileName` with `WorkflowID` in `FindRunOptions` struct in `run_list.go` - Update conditions in `toConds` function to use `WorkflowID` instead of `WorkflowFileName` in `run_list.go` - Replace `WorkflowFileName` with `WorkflowID` in `List` function in `actions.go` Signed-off-by: appleboy <[email protected]>
- Modify the comment for the `CancelRunningJobs` function to specify that it also marks unstarted jobs as cancelled - Change the comment in `notify` function to specify that running jobs are cancelled only if the event is a push - Add a condition in `notify` function to cancel running jobs of the same workflow only if the event is a push Signed-off-by: appleboy <[email protected]>
- Update the `CancelRunningJobs` function to cancel all running and waiting jobs associated with a specific workflow - Modify the function parameters to include `repoID`, `ref`, and `workflowID` - Add checks and conditions to handle different job states during cancellation - Update the call to `CancelRunningJobs` in `notifier_helper.go` to match the new function signature Signed-off-by: appleboy <[email protected]>
- Refactor the `CancelRunningJobs` function parameters for better readability. Signed-off-by: appleboy <[email protected]>
- Add a new migration "Update Action Ref" to the migrations list - Create a new file `v267.go` in `models/migrations/v1_21` directory - Define a new function `UpdateActionsRefIndex` in `v267.go` to update the index of actions ref field - The `UpdateActionsRefIndex` function syncs a new instance of `ActionRun` struct which includes fields like `ID`, `Title`, `RepoID`, `OwnerID`, `WorkflowID`, `Index`, `TriggerUserID`, `Ref`, `CommitSHA`, `IsForkPullRequest`, `NeedApproval`, `ApprovedBy`, `Event`, `EventPayload`, `TriggerEvent`, `Status`, `Started`, `Stopped`, `Created`, `Updated`. Signed-off-by: appleboy <[email protected]>
@wolfogre Please help to review. |
@appleboy please fix the merge conflicts. 🍵 |
Head branch was pushed to by a user without write access
Co-authored-by: delvh <[email protected]>
Co-authored-by: delvh <[email protected]>
Co-authored-by: delvh <[email protected]>
- Update migration version from `v267` to `v269` - Rename migration file from `v267.go` to `v268.go` Signed-off-by: Bo-Yi Wu <[email protected]>
* giteaofficial/main: (23 commits) Avoid writing config file if not installed (go-gitea#26107) Implement auto-cancellation of concurrent jobs if the event is push (go-gitea#25716) [skip ci] Updated translations via Crowdin doc guide the user to create the appropriate level runner (go-gitea#26091) Fix handling of Debian files with trailing slash (go-gitea#26087) fix Missing 404 swagger response docs for /admin/users/{username} (go-gitea#26086) Allow the use of alternative net.Listener implementations by downstreams (go-gitea#25855) Add missing default value for some Bool cli flags (go-gitea#26082) Reduce unnecessary DB queries for Actions tasks (go-gitea#25199) Use stderr as fallback if the log file can't be opened (go-gitea#26074) Make organization redirect warning more clear (go-gitea#26077) Replace gogs/cron with go-co-op/gocron (go-gitea#25977) Remove `db.DefaultContext` in `routers/` and `cmd/` (go-gitea#26076) Categorize admin settings sidebar panel (go-gitea#26030) [skip ci] Updated translations via Crowdin Fix duplicated url prefix on issue context menu (go-gitea#26066) Add context parameter to some database functions (go-gitea#26055) Fix branch list auth (go-gitea#26041) Fix the truncate and alignment problem for some admin tables (go-gitea#26042) Update secrets.en-us.md (go-gitea#26057) ...
CancelRunningJobs
to cancel all running jobs of a runFindRunOptions
struct to includeRef
field and update its condition intoConds
functionnotify
functionrelated task: #22751