Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: introduce stage blocked fields (#4436)

Danny Xu6e0ead78b873
diff --git a/backend/legacyapi/task.go b/backend/legacyapi/task.go
index 466454cd72..b6a8de5549 100644
--- a/backend/legacyapi/task.go
+++ b/backend/legacyapi/task.go
@@ -241,7 +241,8 @@ type Task struct {
// We use string here to workaround jsonapi limitations. https://github.com/google/jsonapi/issues/209
BlockedBy []string `jsonapi:"attr,blockedBy"`
// Progress is loaded from the task scheduler in memory, NOT from the database
- Progress Progress `jsonapi:"attr,progress"`
+ Progress Progress `jsonapi:"attr,progress"`
+ StageBlocked bool
}
// Progress is a generalized struct which can track the progress of a task.
diff --git a/backend/runner/taskrun/scheduler.go b/backend/runner/taskrun/scheduler.go
index e28c6dd5dd..1ae9154d64 100644
--- a/backend/runner/taskrun/scheduler.go
+++ b/backend/runner/taskrun/scheduler.go
@@ -774,8 +774,12 @@ func (s *Scheduler) scheduleAutoApprovedTasks(ctx context.Context) error {
if policy.Value != api.PipelineApprovalValueManualNever {
continue
}
+ // Checks active stage.
+ if task.StageBlocked {
+ continue
+ }
- instance, err := s.store.GetInstanceV2(ctx, &store.FindInstanceMessage{UID: &task.Database.InstanceID})
+ instance, err := s.store.GetInstanceV2(ctx, &store.FindInstanceMessage{UID: &task.InstanceID})
if err != nil {
return err
}
@@ -783,7 +787,6 @@ func (s *Scheduler) scheduleAutoApprovedTasks(ctx context.Context) error {
if err != nil {
return errors.Wrap(err, "failed to check if can auto-approve")
}
- // Checks active stage.
if ok {
if _, err := s.PatchTaskStatus(ctx, task, &api.TaskStatusPatch{
ID: task.ID,
diff --git a/backend/store/task.go b/backend/store/task.go
index ee0a90a51f..388f7f4c33 100644
--- a/backend/store/task.go
+++ b/backend/store/task.go
@@ -40,6 +40,7 @@ type TaskMessage struct {
Payload string
EarliestAllowedTs int64
BlockedBy []string
+ StageBlocked bool
}
func (task *TaskMessage) toTask() *api.Task {
@@ -66,6 +67,7 @@ func (task *TaskMessage) toTask() *api.Task {
Payload: task.Payload,
EarliestAllowedTs: task.EarliestAllowedTs,
BlockedBy: task.BlockedBy,
+ StageBlocked: task.StageBlocked,
}
}
@@ -409,7 +411,8 @@ func (s *Store) ListTasks(ctx context.Context, find *api.TaskFind) ([]*TaskMessa
status,
type,
payload,
- earliest_allowed_ts
+ earliest_allowed_ts,
+ (SELECT COUNT(1) FROM task as other_task WHERE other_task.pipeline_id = task.pipeline_id AND other_task.stage_id < task.stage_id AND other_task.status != 'DONE') as block_count
FROM task
WHERE `+strings.Join(where, " AND ")+` ORDER BY id ASC`,
args...,
@@ -422,6 +425,7 @@ func (s *Store) ListTasks(ctx context.Context, find *api.TaskFind) ([]*TaskMessa
var tasks []*TaskMessage
for rows.Next() {
task := &TaskMessage{}
+ var blockCount int
if err := rows.Scan(
&task.ID,
&task.CreatorID,
@@ -437,9 +441,13 @@ func (s *Store) ListTasks(ctx context.Context, find *api.TaskFind) ([]*TaskMessa
&task.Type,
&task.Payload,
&task.EarliestAllowedTs,
+ &blockCount,
); err != nil {
return nil, err
}
+ if blockCount > 0 {
+ task.StageBlocked = true
+ }
tasks = append(tasks, task)
}
if err := rows.Err(); err != nil {