Skip to content

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

feat: impl taskRun runAt (#16182)

p0nye780936e0efe
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index 8ba1a208ab..4de035c938 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -590,6 +590,10 @@ func (s *RolloutService) BatchRunTasks(ctx context.Context, request *v1pb.BatchR
sheetUID := int(task.Payload.GetSheetId())
create.SheetUID = &sheetUID
}
+ if request.GetRunTime() != nil {
+ t := request.GetRunTime().AsTime()
+ create.RunAt = &t
+ }
taskRunCreates = append(taskRunCreates, create)
}
sort.Slice(taskRunCreates, func(i, j int) bool {
diff --git a/backend/api/v1/rollout_service_converter.go b/backend/api/v1/rollout_service_converter.go
index a2010c620e..fc84e0f21b 100644
--- a/backend/api/v1/rollout_service_converter.go
+++ b/backend/api/v1/rollout_service_converter.go
@@ -487,6 +487,9 @@ func convertToTaskRun(ctx context.Context, s *store.Store, stateCfg *state.State
if taskRun.StartedAt != nil {
t.StartTime = timestamppb.New(*taskRun.StartedAt)
}
+ if taskRun.RunAt != nil {
+ t.RunTime = timestamppb.New(*taskRun.RunAt)
+ }
if taskRun.SheetUID != nil && *taskRun.SheetUID != 0 {
sheet, err := s.GetSheet(ctx, &store.FindSheetMessage{UID: taskRun.SheetUID})
diff --git a/backend/runner/taskrun/schedulerv2.go b/backend/runner/taskrun/schedulerv2.go
index ee4e46fad2..1b8ee5487a 100644
--- a/backend/runner/taskrun/schedulerv2.go
+++ b/backend/runner/taskrun/schedulerv2.go
@@ -283,14 +283,14 @@ func (s *SchedulerV2) schedulePendingTaskRuns(ctx context.Context) error {
func (s *SchedulerV2) schedulePendingTaskRun(ctx context.Context, taskRun *store.TaskRunMessage) error {
// here, we move pending taskruns to running taskruns which means they are ready to be executed.
// pending taskruns remain pending if
- // 1. earliestAllowedTs not met.
+ // 1. taskRun.RunAt not met.
// 2. for versioned tasks, there are other versioned tasks on the same database with
// a smaller version not finished yet. we need to wait for those first.
task, err := s.store.GetTaskV2ByID(ctx, taskRun.TaskUID)
if err != nil {
return errors.Wrapf(err, "failed to get task")
}
- if task.EarliestAllowedAt != nil && time.Now().Before(*task.EarliestAllowedAt) {
+ if taskRun.RunAt != nil && time.Now().Before(*taskRun.RunAt) {
return nil
}
diff --git a/backend/store/task.go b/backend/store/task.go
index 660594ca3a..fbfd73184c 100644
--- a/backend/store/task.go
+++ b/backend/store/task.go
@@ -32,8 +32,9 @@ type TaskMessage struct {
TaskRunRawList []*TaskRunMessage
// Domain specific fields
- Type base.TaskType
- Payload *storepb.TaskPayload
+ Type base.TaskType
+ Payload *storepb.TaskPayload
+ // TODO(p0ny): deprecate
EarliestAllowedAt *time.Time
LatestTaskRunStatus base.TaskRunStatus
diff --git a/backend/store/task_run.go b/backend/store/task_run.go
index 999889026b..53c340db94 100644
--- a/backend/store/task_run.go
+++ b/backend/store/task_run.go
@@ -34,6 +34,7 @@ type TaskRunMessage struct {
UpdatedAt time.Time
ProjectID string
StartedAt *time.Time
+ RunAt *time.Time
}
// FindTaskRunMessage is the message for finding task runs.
@@ -106,6 +107,7 @@ func (s *Store) ListTaskRunsV2(ctx context.Context, find *FindTaskRunMessage) ([
task_run.task_id,
task_run.status,
task_run.started_at,
+ task_run.run_at,
task_run.code,
task_run.result,
task_run.sheet_id,
@@ -128,7 +130,7 @@ func (s *Store) ListTaskRunsV2(ctx context.Context, find *FindTaskRunMessage) ([
var taskRuns []*TaskRunMessage
for rows.Next() {
var taskRun TaskRunMessage
- var startedAt sql.NullTime
+ var startedAt, runAt sql.NullTime
if err := rows.Scan(
&taskRun.ID,
&taskRun.CreatorID,
@@ -137,6 +139,7 @@ func (s *Store) ListTaskRunsV2(ctx context.Context, find *FindTaskRunMessage) ([
&taskRun.TaskUID,
&taskRun.Status,
&startedAt,
+ &runAt,
&taskRun.Code,
&taskRun.Result,
&taskRun.SheetUID,
@@ -150,6 +153,9 @@ func (s *Store) ListTaskRunsV2(ctx context.Context, find *FindTaskRunMessage) ([
if startedAt.Valid {
taskRun.StartedAt = &startedAt.Time
}
+ if runAt.Valid {
+ taskRun.RunAt = &runAt.Time
+ }
var resultProto storepb.TaskRunResult
if err := common.ProtojsonUnmarshaler.Unmarshal([]byte(taskRun.Result), &resultProto); err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal task run result: %s", taskRun.Result)
@@ -321,14 +327,16 @@ func (*Store) createTaskRunImpl(ctx context.Context, txn *sql.Tx, create *TaskRu
creator_id,
task_id,
sheet_id,
+ run_at,
attempt,
status
- ) VALUES ($1, $2, $3, $4, $5)
+ ) VALUES ($1, $2, $3, $4, $5, $6)
`
if _, err := txn.ExecContext(ctx, query,
creatorID,
create.TaskUID,
create.SheetUID,
+ create.RunAt,
attempt,
status,
); err != nil {