diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 0203bf2307359..8daab1b9958e1 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -442,8 +442,35 @@ func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob, shou job.Started = 0 job.Stopped = 0 + job.ConcurrencyGroup = "" + job.ConcurrencyCancel = false + job.IsConcurrencyEvaluated = false + if err := job.LoadRun(ctx); err != nil { + return err + } + vars, err := actions_model.GetVariablesOfRun(ctx, job.Run) + if err != nil { + return fmt.Errorf("get run %d variables: %w", job.Run.ID, err) + } + if job.RawConcurrencyGroup != "" && job.Status != actions_model.StatusBlocked { + var err error + job.ConcurrencyGroup, job.ConcurrencyCancel, err = actions_service.EvaluateJobConcurrency(job.Run, job, vars, nil) + if err != nil { + return fmt.Errorf("evaluate job concurrency: %w", err) + } + job.IsConcurrencyEvaluated = true + blockByConcurrency, err := actions_model.ShouldBlockJobByConcurrency(ctx, job) + if err != nil { + return err + } + if blockByConcurrency { + job.Status = actions_model.StatusBlocked + } + } + if err := db.WithTx(ctx, func(ctx context.Context) error { - _, err := actions_model.UpdateRunJob(ctx, job, builder.Eq{"status": status}, "task_id", "status", "started", "stopped") + updateCols := []string{"task_id", "status", "started", "stopped", "concurrency_group", "concurrency_cancel", "is_concurrency_evaluated"} + _, err := actions_model.UpdateRunJob(ctx, job, builder.Eq{"status": status}, updateCols...) return err }); err != nil { return err diff --git a/services/actions/concurrency.go b/services/actions/concurrency.go index 5a40d30cf3967..7a5c24bd5a976 100644 --- a/services/actions/concurrency.go +++ b/services/actions/concurrency.go @@ -12,7 +12,7 @@ import ( act_model "github.com/nektos/act/pkg/model" ) -func evaluateJobConcurrency(run *actions_model.ActionRun, actionRunJob *actions_model.ActionRunJob, vars map[string]string, jobResults map[string]*jobparser.JobResult) (string, bool, error) { +func EvaluateJobConcurrency(run *actions_model.ActionRun, actionRunJob *actions_model.ActionRunJob, vars map[string]string, jobResults map[string]*jobparser.JobResult) (string, bool, error) { rawConcurrency := &act_model.RawConcurrency{ Group: actionRunJob.RawConcurrencyGroup, CancelInProgress: actionRunJob.RawConcurrencyCancel, diff --git a/services/actions/job_emitter.go b/services/actions/job_emitter.go index 855edea122e99..0f3135b4e7cca 100644 --- a/services/actions/job_emitter.go +++ b/services/actions/job_emitter.go @@ -291,7 +291,7 @@ func checkConcurrencyForJobWithNeeds(ctx context.Context, actionRunJob *actions_ jobResults[jobID] = jobResult } - actionRunJob.ConcurrencyGroup, actionRunJob.ConcurrencyCancel, err = evaluateJobConcurrency(actionRunJob.Run, actionRunJob, vars, jobResults) + actionRunJob.ConcurrencyGroup, actionRunJob.ConcurrencyCancel, err = EvaluateJobConcurrency(actionRunJob.Run, actionRunJob, vars, jobResults) if err != nil { return false, fmt.Errorf("evaluate job concurrency: %w", err) } diff --git a/services/actions/run.go b/services/actions/run.go index b1a3613360d76..95e078f90a60a 100644 --- a/services/actions/run.go +++ b/services/actions/run.go @@ -93,13 +93,13 @@ func InsertRun(ctx context.Context, run *actions_model.ActionRun, jobs []*jobpar } // check job concurrency - if job.RawConcurrency != nil && len(job.RawConcurrency.Group) > 0 { + if job.RawConcurrency != nil && job.RawConcurrency.Group != "" { runJob.RawConcurrencyGroup = job.RawConcurrency.Group runJob.RawConcurrencyCancel = job.RawConcurrency.CancelInProgress // we do not need to evaluate job concurrency if the job is blocked because it will be checked by job emitter if runJob.Status != actions_model.StatusBlocked { var err error - runJob.ConcurrencyGroup, runJob.ConcurrencyCancel, err = evaluateJobConcurrency(run, runJob, vars, map[string]*jobparser.JobResult{}) + runJob.ConcurrencyGroup, runJob.ConcurrencyCancel, err = EvaluateJobConcurrency(run, runJob, vars, nil) if err != nil { return fmt.Errorf("evaluate job concurrency: %w", err) }