diff --git a/models/bots/run_job.go b/models/bots/run_job.go index f421ed6cfa..7162b18116 100644 --- a/models/bots/run_job.go +++ b/models/bots/run_job.go @@ -24,15 +24,15 @@ type RunJob struct { Name string Attempt int64 WorkflowPayload []byte - JobID string // job id in workflow, not job's id - Needs []string `xorm:"JSON TEXT"` - RunsOn []string `xorm:"JSON TEXT"` - TaskID int64 // the latest task of the job - Status Status `xorm:"index"` - Started timeutil.TimeStamp `xorm:"index"` + JobID string // job id in workflow, not job's id + Needs []string `xorm:"JSON TEXT"` + RunsOn []string `xorm:"JSON TEXT"` + TaskID int64 // the latest task of the job + Status Status `xorm:"index"` + Started timeutil.TimeStamp Stopped timeutil.TimeStamp Created timeutil.TimeStamp `xorm:"created"` - Updated timeutil.TimeStamp `xorm:"updated"` + Updated timeutil.TimeStamp `xorm:"updated index"` } func init() { diff --git a/models/bots/run_job_list.go b/models/bots/run_job_list.go index d4276315f9..292774a42b 100644 --- a/models/bots/run_job_list.go +++ b/models/bots/run_job_list.go @@ -61,7 +61,7 @@ type FindRunJobOptions struct { db.ListOptions RunID int64 Statuses []Status - StartedBefore timeutil.TimeStamp + UpdatedBefore timeutil.TimeStamp } func (opts FindRunJobOptions) toConds() builder.Cond { @@ -72,8 +72,8 @@ func (opts FindRunJobOptions) toConds() builder.Cond { if len(opts.Statuses) > 0 { cond = cond.And(builder.In("status", opts.Statuses)) } - if opts.StartedBefore > 0 { - cond = cond.And(builder.Lt{"started": opts.StartedBefore}) + if opts.UpdatedBefore > 0 { + cond = cond.And(builder.Lt{"updated": opts.UpdatedBefore}) } return cond } diff --git a/models/migrations/v-dev.go b/models/migrations/v-dev.go index 64616ec258..73c23c1482 100644 --- a/models/migrations/v-dev.go +++ b/models/migrations/v-dev.go @@ -81,7 +81,7 @@ func addBotTables(x *xorm.Engine) error { Started timeutil.TimeStamp Stopped timeutil.TimeStamp Created timeutil.TimeStamp `xorm:"created"` - Updated timeutil.TimeStamp `xorm:"updated"` + Updated timeutil.TimeStamp `xorm:"updated index"` } type Repository struct { diff --git a/services/bots/clear_tasks.go b/services/bots/clear_tasks.go index d6c59986ce..a525b50e05 100644 --- a/services/bots/clear_tasks.go +++ b/services/bots/clear_tasks.go @@ -65,7 +65,7 @@ func StopEndlessTasks(ctx context.Context) error { func CancelAbandonedJobs(ctx context.Context) error { jobs, _, err := bots_model.FindRunJobs(ctx, bots_model.FindRunJobOptions{ Statuses: []bots_model.Status{bots_model.StatusWaiting, bots_model.StatusBlocked}, - StartedBefore: timeutil.TimeStamp(time.Now().Add(-abandonedJobTimeout).Unix()), + UpdatedBefore: timeutil.TimeStamp(time.Now().Add(-abandonedJobTimeout).Unix()), }) if err != nil { log.Warn("find abandoned tasks: %v", err)