Skip to content

Commit

Permalink
fix job concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
Zettat123 committed Jan 20, 2025
1 parent ffa0109 commit fc3188e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion routers/web/repo/actions/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob, shou
}
if job.RawConcurrencyGroup != "" && job.Status != actions_model.StatusBlocked {
var err error
job.ConcurrencyGroup, job.ConcurrencyCancel, err = actions_service.EvaluateJobConcurrency(job.Run, job, vars, nil)
job.ConcurrencyGroup, job.ConcurrencyCancel, err = actions_service.EvaluateJobConcurrency(ctx, job.Run, job, vars, nil)
if err != nil {
return fmt.Errorf("evaluate job concurrency: %w", err)
}
Expand Down
23 changes: 14 additions & 9 deletions services/actions/concurrency.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func EvaluateWorkflowConcurrency(ctx context.Context, run *actions_model.ActionR
if err := run.LoadAttributes(ctx); err != nil {
return "", false, fmt.Errorf("run LoadAttributes: %w", err)
}

gitCtx := jobparser.ToGitContext(GenerateGiteaContext(run, nil))

Check failure on line 23 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / backend

undefined: jobparser.ToGitContext

Check failure on line 23 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-pgsql

undefined: jobparser.ToGitContext

Check failure on line 23 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-sqlite

undefined: jobparser.ToGitContext

Check failure on line 23 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-unit

undefined: jobparser.ToGitContext

Check failure on line 23 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mysql

undefined: jobparser.ToGitContext

Check failure on line 23 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mssql

undefined: jobparser.ToGitContext

Check failure on line 23 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-e2e

undefined: jobparser.ToGitContext

Check failure on line 23 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-backend

undefined: jobparser.ToGitContext

Check failure on line 23 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

undefined: jobparser.ToGitContext

Check failure on line 23 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

undefined: jobparser.ToGitContext
jobResults := map[string]*jobparser.JobResult{"": {}}
inputs, err := getInputsFromRun(run)
Expand All @@ -34,20 +35,16 @@ func EvaluateWorkflowConcurrency(ctx context.Context, run *actions_model.ActionR
return concurrencyGroup, concurrencyCancel, nil
}

func EvaluateJobConcurrency(run *actions_model.ActionRun, actionRunJob *actions_model.ActionRunJob, vars map[string]string, jobResults map[string]*jobparser.JobResult) (string, bool, error) {
func EvaluateJobConcurrency(ctx context.Context, run *actions_model.ActionRun, actionRunJob *actions_model.ActionRunJob, vars map[string]string, jobResults map[string]*jobparser.JobResult) (string, bool, error) {
if err := actionRunJob.LoadAttributes(ctx); err != nil {
return "", false, fmt.Errorf("job LoadAttributes: %w", err)
}

rawConcurrency := &act_model.RawConcurrency{

Check failure on line 43 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / backend

undefined: act_model.RawConcurrency

Check failure on line 43 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-pgsql

undefined: act_model.RawConcurrency

Check failure on line 43 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-sqlite

undefined: act_model.RawConcurrency

Check failure on line 43 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-unit

undefined: act_model.RawConcurrency

Check failure on line 43 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mysql

undefined: act_model.RawConcurrency

Check failure on line 43 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mssql

undefined: act_model.RawConcurrency

Check failure on line 43 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-e2e

undefined: act_model.RawConcurrency

Check failure on line 43 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-backend

undefined: act_model.RawConcurrency

Check failure on line 43 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

undefined: act_model.RawConcurrency

Check failure on line 43 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

undefined: act_model.RawConcurrency
Group: actionRunJob.RawConcurrencyGroup,
CancelInProgress: actionRunJob.RawConcurrencyCancel,
}

singleWorkflows, err := jobparser.Parse([]byte(actionRunJob.WorkflowPayload))
if err != nil {
return "", false, fmt.Errorf("parse single workflow: %w", err)
} else if len(singleWorkflows) != 1 {
return "", false, fmt.Errorf("not single workflow")
}
_, singleWorkflowJob := singleWorkflows[0].Job()

gitCtx := jobparser.ToGitContext(GenerateGiteaContext(run, actionRunJob))

Check failure on line 48 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / backend

undefined: jobparser.ToGitContext

Check failure on line 48 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-pgsql

undefined: jobparser.ToGitContext

Check failure on line 48 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-sqlite

undefined: jobparser.ToGitContext

Check failure on line 48 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-unit

undefined: jobparser.ToGitContext

Check failure on line 48 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mysql

undefined: jobparser.ToGitContext

Check failure on line 48 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mssql

undefined: jobparser.ToGitContext

Check failure on line 48 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-e2e

undefined: jobparser.ToGitContext

Check failure on line 48 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-backend

undefined: jobparser.ToGitContext

Check failure on line 48 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

undefined: jobparser.ToGitContext

Check failure on line 48 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

undefined: jobparser.ToGitContext
if jobResults == nil {
jobResults = map[string]*jobparser.JobResult{}
Expand All @@ -60,6 +57,14 @@ func EvaluateJobConcurrency(run *actions_model.ActionRun, actionRunJob *actions_
return "", false, fmt.Errorf("get inputs: %w", err)
}

singleWorkflows, err := jobparser.Parse([]byte(actionRunJob.WorkflowPayload))
if err != nil {
return "", false, fmt.Errorf("parse single workflow: %w", err)
} else if len(singleWorkflows) != 1 {
return "", false, fmt.Errorf("not single workflow")
}
_, singleWorkflowJob := singleWorkflows[0].Job()

concurrencyGroup, concurrencyCancel, err := jobparser.EvaluateConcurrency(rawConcurrency, actionRunJob.JobID, singleWorkflowJob, gitCtx, jobResults, vars, inputs)

Check failure on line 68 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / backend

undefined: jobparser.EvaluateConcurrency

Check failure on line 68 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-pgsql

undefined: jobparser.EvaluateConcurrency

Check failure on line 68 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-sqlite

undefined: jobparser.EvaluateConcurrency

Check failure on line 68 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-unit

undefined: jobparser.EvaluateConcurrency

Check failure on line 68 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mysql

undefined: jobparser.EvaluateConcurrency

Check failure on line 68 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mssql

undefined: jobparser.EvaluateConcurrency

Check failure on line 68 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-e2e

undefined: jobparser.EvaluateConcurrency

Check failure on line 68 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-backend

undefined: jobparser.EvaluateConcurrency

Check failure on line 68 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

undefined: jobparser.EvaluateConcurrency

Check failure on line 68 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

undefined: jobparser.EvaluateConcurrency
if err != nil {
return "", false, fmt.Errorf("evaluate concurrency: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion services/actions/job_emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(ctx, actionRunJob.Run, actionRunJob, vars, jobResults)
if err != nil {
return false, fmt.Errorf("evaluate job concurrency: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion services/actions/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func InsertRun(ctx context.Context, run *actions_model.ActionRun, jobs []*jobpar
// 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, nil)
runJob.ConcurrencyGroup, runJob.ConcurrencyCancel, err = EvaluateJobConcurrency(ctx, run, runJob, vars, nil)
if err != nil {
return fmt.Errorf("evaluate job concurrency: %w", err)
}
Expand Down

0 comments on commit fc3188e

Please sign in to comment.