1
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-04-18 00:47:48 -04:00

fix: use updated to check abandoned jobs

This commit is contained in:
Jason Song 2022-11-07 15:09:13 +08:00
parent 0b62e1da74
commit cab3fc072a
4 changed files with 12 additions and 12 deletions

View File

@ -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() {

View File

@ -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
}

View File

@ -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 {

View File

@ -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)