mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-07 14:22:06 +00:00
c210ef6dbb
My idea is to allow cancelling an stuck run with all jobs done, in case such a bug happens again to not require admin commands. Related #35832 Co-authored-by: Zettat123 <zettat123@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
actions_model "gitea.dev/models/actions"
|
|
"gitea.dev/models/db"
|
|
)
|
|
|
|
// CancelRun cancels a run's cancellable jobs and returns the run's post-cancellation state.
|
|
func CancelRun(ctx context.Context, run *actions_model.ActionRun, jobs []*actions_model.ActionRunJob) (*actions_model.ActionRun, error) {
|
|
var updatedJobs []*actions_model.ActionRunJob
|
|
if err := db.WithTx(ctx, func(ctx context.Context) (err error) {
|
|
updatedJobs, err = actions_model.CancelJobs(ctx, jobs)
|
|
if err != nil {
|
|
return fmt.Errorf("CancelJobs: %w", err)
|
|
}
|
|
if len(updatedJobs) > 0 {
|
|
return nil // a job update already refreshed the run
|
|
}
|
|
return actions_model.SettleRunAfterCancel(ctx, run)
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
CreateCommitStatusForRunJobs(ctx, run, jobs...)
|
|
EmitJobsIfReadyByJobs(updatedJobs)
|
|
NotifyWorkflowJobsStatusUpdate(ctx, updatedJobs...)
|
|
|
|
reloaded, err := actions_model.GetRunByRepoAndID(ctx, run.RepoID, run.ID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("GetRunByRepoAndID: %w", err)
|
|
}
|
|
if len(updatedJobs) > 0 || reloaded.Status != run.Status {
|
|
NotifyWorkflowRunStatusUpdate(ctx, reloaded)
|
|
}
|
|
return reloaded, nil
|
|
}
|