mirror of
https://github.com/go-gitea/gitea.git
synced 2024-09-01 14:56:30 +00:00
feat: record job needs
This commit is contained in:
parent
234cdc67e1
commit
cf40dca0c4
@ -14,10 +14,10 @@ import (
|
|||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/models/webhook"
|
"code.gitea.io/gitea/models/webhook"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
|
|
||||||
"github.com/nektos/act/pkg/jobparser"
|
"github.com/nektos/act/pkg/jobparser"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
@ -167,15 +167,19 @@ func InsertRun(run *Run, jobs []*jobparser.SingleWorkflow) error {
|
|||||||
for _, v := range jobs {
|
for _, v := range jobs {
|
||||||
id, job := v.Job()
|
id, job := v.Job()
|
||||||
payload, _ := v.Marshal()
|
payload, _ := v.Marshal()
|
||||||
|
needs := job.Needs()
|
||||||
|
status := StatusWaiting
|
||||||
|
if len(needs) > 0 {
|
||||||
|
status = StatusBlocked
|
||||||
|
}
|
||||||
runJobs = append(runJobs, &RunJob{
|
runJobs = append(runJobs, &RunJob{
|
||||||
RunID: run.ID,
|
RunID: run.ID,
|
||||||
Name: job.Name,
|
Name: job.Name,
|
||||||
Ready: true, // TODO: should be false if there are needs to satisfy
|
|
||||||
WorkflowPayload: payload,
|
WorkflowPayload: payload,
|
||||||
JobID: id,
|
JobID: id,
|
||||||
Needs: nil, // TODO: analyse needs
|
Needs: needs,
|
||||||
RunsOn: job.RunsOn(),
|
RunsOn: job.RunsOn(),
|
||||||
Status: StatusWaiting,
|
Status: status,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if err := db.Insert(ctx, runJobs); err != nil {
|
if err := db.Insert(ctx, runJobs); err != nil {
|
||||||
|
@ -22,11 +22,10 @@ type RunJob struct {
|
|||||||
RunID int64 `xorm:"index"`
|
RunID int64 `xorm:"index"`
|
||||||
Run *Run `xorm:"-"`
|
Run *Run `xorm:"-"`
|
||||||
Name string
|
Name string
|
||||||
Ready bool // ready to be executed
|
|
||||||
Attempt int64
|
Attempt int64
|
||||||
WorkflowPayload []byte
|
WorkflowPayload []byte
|
||||||
JobID string // job id in workflow, not job's id
|
JobID string // job id in workflow, not job's id
|
||||||
Needs []int64 `xorm:"JSON TEXT"`
|
Needs []string `xorm:"JSON TEXT"`
|
||||||
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"`
|
||||||
|
@ -16,14 +16,14 @@ type RunJobList []*RunJob
|
|||||||
|
|
||||||
type FindRunJobOptions struct {
|
type FindRunJobOptions struct {
|
||||||
db.ListOptions
|
db.ListOptions
|
||||||
Status Status
|
Statuses []Status
|
||||||
StartedBefore timeutil.TimeStamp
|
StartedBefore timeutil.TimeStamp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts FindRunJobOptions) toConds() builder.Cond {
|
func (opts FindRunJobOptions) toConds() builder.Cond {
|
||||||
cond := builder.NewCond()
|
cond := builder.NewCond()
|
||||||
if opts.Status > StatusUnknown {
|
if len(opts.Statuses) > 0 {
|
||||||
cond = cond.And(builder.Eq{"status": opts.Status})
|
cond = cond.And(builder.In("status", opts.Statuses))
|
||||||
}
|
}
|
||||||
if opts.StartedBefore > 0 {
|
if opts.StartedBefore > 0 {
|
||||||
cond = cond.And(builder.Lt{"started": opts.StartedBefore})
|
cond = cond.And(builder.Lt{"started": opts.StartedBefore})
|
||||||
|
@ -15,6 +15,7 @@ const (
|
|||||||
StatusSkipped // 4, consistent with runnerv1.Result_RESULT_SKIPPED
|
StatusSkipped // 4, consistent with runnerv1.Result_RESULT_SKIPPED
|
||||||
StatusWaiting // 5
|
StatusWaiting // 5
|
||||||
StatusRunning // 6
|
StatusRunning // 6
|
||||||
|
StatusBlocked // 7
|
||||||
)
|
)
|
||||||
|
|
||||||
// String returns the string name of the Status
|
// String returns the string name of the Status
|
||||||
|
@ -242,7 +242,7 @@ func CreateTaskForRunner(ctx context.Context, runner *Runner) (*Task, bool, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
var jobs []*RunJob
|
var jobs []*RunJob
|
||||||
if err := e.Where("task_id=? AND ready=?", 0, true).And(jobCond).OrderBy("id").Find(&jobs); err != nil {
|
if err := e.Where("task_id=? AND status=?", 0, StatusWaiting).And(jobCond).Asc("id").Find(&jobs); err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,11 +71,10 @@ func addBotTables(x *xorm.Engine) error {
|
|||||||
ID int64
|
ID int64
|
||||||
RunID int64 `xorm:"index"`
|
RunID int64 `xorm:"index"`
|
||||||
Name string
|
Name string
|
||||||
Ready bool // ready to be executed
|
|
||||||
Attempt int64
|
Attempt int64
|
||||||
WorkflowPayload []byte
|
WorkflowPayload []byte
|
||||||
JobID string // job id in workflow, not job's id
|
JobID string // job id in workflow, not job's id
|
||||||
Needs []int64 `xorm:"JSON TEXT"`
|
Needs []string `xorm:"JSON TEXT"`
|
||||||
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 int `xorm:"index"`
|
Status int `xorm:"index"`
|
||||||
|
@ -64,7 +64,7 @@ func StopEndlessTasks(ctx context.Context) error {
|
|||||||
// CancelAbandonedJobs cancels the jobs which have waiting status, but haven't been picked by a runner for a long time
|
// CancelAbandonedJobs cancels the jobs which have waiting status, but haven't been picked by a runner for a long time
|
||||||
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{
|
||||||
Status: bots_model.StatusWaiting,
|
Statuses: []bots_model.Status{bots_model.StatusWaiting, bots_model.StatusBlocked},
|
||||||
StartedBefore: timeutil.TimeStamp(time.Now().Add(-abandonedJobTimeout).Unix()),
|
StartedBefore: timeutil.TimeStamp(time.Now().Add(-abandonedJobTimeout).Unix()),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user