implement evaluate concurrency expression again, vars may change after the run is done

This commit is contained in:
Christopher Homberger 2025-07-25 16:38:35 +02:00
parent 5e43aa2251
commit d5f6c44a49
3 changed files with 50 additions and 28 deletions

View File

@ -48,6 +48,8 @@ type ActionRun struct {
TriggerEvent string // the trigger event defined in the `on` configuration of the triggered workflow
Status Status `xorm:"index"`
Version int `xorm:"version default 0"` // Status could be updated concomitantly, so an optimistic lock is needed
RawConcurrencyGroup string
RawConcurrencyCancel string
ConcurrencyGroup string `xorm:"index(repo_concurrency)"`
ConcurrencyCancel bool
// Started and Stopped is used for recording last run time, if rerun happened, they will be reset to 0

View File

@ -10,6 +10,8 @@ import (
func AddActionsConcurrency(x *xorm.Engine) error {
type ActionRun struct {
RepoID int64 `xorm:"index unique(repo_index) index(repo_concurrency)"`
RawConcurrencyGroup string
RawConcurrencyCancel string
ConcurrencyGroup string `xorm:"index(repo_concurrency)"`
ConcurrencyCancel bool
}

View File

@ -419,7 +419,6 @@ func Rerun(ctx *context_module.Context) {
return
}
// TODO evaluate concurrency expression again, vars may change after the run is done
// check run (workflow-level) concurrency
job, jobs := getRunJobs(ctx, runIndex, jobIndex)
@ -435,6 +434,25 @@ func Rerun(ctx *context_module.Context) {
run.Started = 0
run.Stopped = 0
vars, err := actions_model.GetVariablesOfRun(ctx, run)
if err != nil {
ctx.ServerError("GetVariablesOfRun", fmt.Errorf("get run %d variables: %w", run.ID, err))
return
}
wfConcurrencyGroup, wfConcurrencyCancel, err := actions_service.EvaluateWorkflowConcurrency(ctx, run, &model.RawConcurrency{
Group: run.RawConcurrencyGroup,
CancelInProgress: run.RawConcurrencyCancel,
}, vars)
if err != nil {
ctx.ServerError("EvaluateWorkflowConcurrency", fmt.Errorf("evaluate workflow concurrency: %w", err))
return
}
if wfConcurrencyGroup != "" {
run.ConcurrencyGroup = wfConcurrencyGroup
run.ConcurrencyCancel = wfConcurrencyCancel
}
blockRunByConcurrency, err = actions_model.ShouldBlockRunByConcurrency(ctx, run)
if err != nil {
ctx.ServerError("ShouldBlockRunByConcurrency", err)
@ -449,7 +467,7 @@ func Rerun(ctx *context_module.Context) {
ctx.ServerError("cancel jobs", err)
return
}
if err := actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration", "status"); err != nil {
if err := actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration", "status", "concurrency_group", "concurrency_cancel"); err != nil {
ctx.ServerError("UpdateRun", err)
return
}