Implement auto-cancellation of concurrent jobs if the event is push#25716
Merged
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 <appleboy.tw@gmail.com>
- 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 <appleboy.tw@gmail.com>
wolfogre
reviewed
Jul 6, 2023
| } | ||
|
|
||
| // auto cancel running jobs in the same workflow | ||
| if err := actions_model.CancelRunningJobs(ctx, run); err != nil { |
Member
There was a problem hiding this comment.
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.
- 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 <appleboy.tw@gmail.com>
- 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 <appleboy.tw@gmail.com>
Member
|
Done |
wolfogre
reviewed
Jul 10, 2023
Co-authored-by: Jason Song <i@wolfogre.com>
Member
|
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 <appleboy.tw@gmail.com>
- 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 <appleboy.tw@gmail.com>
wolfogre
reviewed
Jul 21, 2023
- 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 <appleboy.tw@gmail.com>
- Refactor the `CancelRunningJobs` function parameters for better readability. Signed-off-by: appleboy <appleboy.tw@gmail.com>
- 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 <appleboy.tw@gmail.com>
lunny
approved these changes
Jul 21, 2023
lunny
reviewed
Jul 22, 2023
Member
Author
|
@wolfogre Please help to review. |
wolfogre
reviewed
Jul 24, 2023
wolfogre
approved these changes
Jul 24, 2023
Collaborator
|
@appleboy please fix the merge conflicts. 🍵 |
delvh
reviewed
Jul 24, 2023
auto-merge was automatically disabled
July 24, 2023 23:23
Head branch was pushed to by a user without write access
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: delvh <dev.lh@web.de>
wolfogre
reviewed
Jul 25, 2023
- Update migration version from `v267` to `v269` - Rename migration file from `v267.go` to `v268.go` Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
zjjhot
added a commit
to zjjhot/gitea
that referenced
this pull request
Jul 25, 2023
* 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) ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CancelRunningJobsto cancel all running jobs of a runFindRunOptionsstruct to includeReffield and update its condition intoCondsfunctionnotifyfunctionrelated task: #22751