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:
parent
0b62e1da74
commit
cab3fc072a
@ -29,10 +29,10 @@ type RunJob struct {
|
|||||||
RunsOn []string `xorm:"JSON TEXT"`
|
RunsOn []string `xorm:"JSON TEXT"`
|
||||||
TaskID int64 // the latest task of the job
|
TaskID int64 // the latest task of the job
|
||||||
Status Status `xorm:"index"`
|
Status Status `xorm:"index"`
|
||||||
Started timeutil.TimeStamp `xorm:"index"`
|
Started timeutil.TimeStamp
|
||||||
Stopped timeutil.TimeStamp
|
Stopped timeutil.TimeStamp
|
||||||
Created timeutil.TimeStamp `xorm:"created"`
|
Created timeutil.TimeStamp `xorm:"created"`
|
||||||
Updated timeutil.TimeStamp `xorm:"updated"`
|
Updated timeutil.TimeStamp `xorm:"updated index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -61,7 +61,7 @@ type FindRunJobOptions struct {
|
|||||||
db.ListOptions
|
db.ListOptions
|
||||||
RunID int64
|
RunID int64
|
||||||
Statuses []Status
|
Statuses []Status
|
||||||
StartedBefore timeutil.TimeStamp
|
UpdatedBefore timeutil.TimeStamp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts FindRunJobOptions) toConds() builder.Cond {
|
func (opts FindRunJobOptions) toConds() builder.Cond {
|
||||||
@ -72,8 +72,8 @@ func (opts FindRunJobOptions) toConds() builder.Cond {
|
|||||||
if len(opts.Statuses) > 0 {
|
if len(opts.Statuses) > 0 {
|
||||||
cond = cond.And(builder.In("status", opts.Statuses))
|
cond = cond.And(builder.In("status", opts.Statuses))
|
||||||
}
|
}
|
||||||
if opts.StartedBefore > 0 {
|
if opts.UpdatedBefore > 0 {
|
||||||
cond = cond.And(builder.Lt{"started": opts.StartedBefore})
|
cond = cond.And(builder.Lt{"updated": opts.UpdatedBefore})
|
||||||
}
|
}
|
||||||
return cond
|
return cond
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ func addBotTables(x *xorm.Engine) error {
|
|||||||
Started timeutil.TimeStamp
|
Started timeutil.TimeStamp
|
||||||
Stopped timeutil.TimeStamp
|
Stopped timeutil.TimeStamp
|
||||||
Created timeutil.TimeStamp `xorm:"created"`
|
Created timeutil.TimeStamp `xorm:"created"`
|
||||||
Updated timeutil.TimeStamp `xorm:"updated"`
|
Updated timeutil.TimeStamp `xorm:"updated index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
|
@ -65,7 +65,7 @@ func StopEndlessTasks(ctx context.Context) error {
|
|||||||
func CancelAbandonedJobs(ctx context.Context) error {
|
func CancelAbandonedJobs(ctx context.Context) error {
|
||||||
jobs, _, err := bots_model.FindRunJobs(ctx, bots_model.FindRunJobOptions{
|
jobs, _, err := bots_model.FindRunJobs(ctx, bots_model.FindRunJobOptions{
|
||||||
Statuses: []bots_model.Status{bots_model.StatusWaiting, bots_model.StatusBlocked},
|
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 {
|
if err != nil {
|
||||||
log.Warn("find abandoned tasks: %v", err)
|
log.Warn("find abandoned tasks: %v", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user