Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): skip booked jobs in queue #6711

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions engine/api/workflow/dao_node_run_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import (

// QueueFilter contains all criteria used to fetch queue
type QueueFilter struct {
ModelType []string
Rights int
Since *time.Time
Until *time.Time
Limit *int
Statuses []string
Regions []string
ModelType []string
Rights int
Since *time.Time
Until *time.Time
Limit *int
Statuses []string
Regions []string
SkipBooked bool
}

func NewQueueFilter() QueueFilter {
Expand Down Expand Up @@ -101,7 +102,7 @@ func LoadNodeJobRunQueue(ctx context.Context, db gorp.SqlExecutor, store cache.S
pq.StringArray(filter.Regions), // $5
)

return loadNodeJobRunQueue(ctx, db, store, query, filter.Limit)
return loadNodeJobRunQueue(ctx, db, store, query, filter.Limit, filter.SkipBooked)
}

// LoadNodeJobRunQueueByGroupIDs load all workflow_node_run_job accessible
Expand Down Expand Up @@ -179,10 +180,10 @@ func LoadNodeJobRunQueueByGroupIDs(ctx context.Context, db gorp.SqlExecutor, sto
filter.Rights, // $7
pq.StringArray(filter.Regions), // $8
)
return loadNodeJobRunQueue(ctx, db, store, query, filter.Limit)
return loadNodeJobRunQueue(ctx, db, store, query, filter.Limit, filter.SkipBooked)
}

func loadNodeJobRunQueue(ctx context.Context, db gorp.SqlExecutor, store cache.Store, query gorpmapping.Query, limit *int) ([]sdk.WorkflowNodeJobRun, error) {
func loadNodeJobRunQueue(ctx context.Context, db gorp.SqlExecutor, store cache.Store, query gorpmapping.Query, limit *int, skipBooked bool) ([]sdk.WorkflowNodeJobRun, error) {
ctx, end := telemetry.Span(ctx, "workflow.loadNodeJobRunQueue")
defer end()

Expand All @@ -199,6 +200,10 @@ func loadNodeJobRunQueue(ctx context.Context, db gorp.SqlExecutor, store cache.S
jobs := make([]sdk.WorkflowNodeJobRun, 0, len(sqlJobs))
for i := range sqlJobs {
getHatcheryInfo(ctx, store, &sqlJobs[i])
if skipBooked && sqlJobs[i].BookedBy.ID != 0 {
log.Info(ctx, "LoadNodeJobRunQueue> WorkflowNodeRunJob %d skipped (booked by %q)", sqlJobs[i].ID, sqlJobs[i].BookedBy.Name)
continue
}
jr, err := sqlJobs[i].WorkflowNodeRunJob()
if err != nil {
log.Error(ctx, "LoadNodeJobRunQueue> WorkflowNodeRunJob error: %v", err)
Expand Down
3 changes: 3 additions & 0 deletions engine/api/workflow_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,9 @@ func (api *API) getWorkflowJobQueueHandler() service.Handler {
if modelType != "" {
filter.ModelType = []string{modelType}
}
if ok, _ := isHatchery(ctx); ok {
filter.SkipBooked = true
}

// If the consumer is a hatchery or a non maintainer user, filter the job by its groups
if isS || !isMaintainer(ctx) {
Expand Down