diff --git a/models/bots/task.go b/models/bots/task.go index 9ba114e203..3589e36f4f 100644 --- a/models/bots/task.go +++ b/models/bots/task.go @@ -22,13 +22,13 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" - runnerv1 "gitea.com/gitea/proto-go/runner/v1" - "xorm.io/builder" + runnerv1 "gitea.com/gitea/proto-go/runner/v1" gouuid "github.com/google/uuid" lru "github.com/hashicorp/golang-lru" "github.com/nektos/act/pkg/jobparser" "google.golang.org/protobuf/types/known/timestamppb" + "xorm.io/builder" ) // Task represents a distribution of job @@ -44,6 +44,10 @@ type Task struct { Started timeutil.TimeStamp `xorm:"index"` Stopped timeutil.TimeStamp + RepoID int64 `xorm:"index"` + OwnerID int64 `xorm:"index"` + CommitSHA string `xorm:"index"` + Token string `xorm:"-"` TokenHash string `xorm:"UNIQUE"` // sha256 of token TokenSalt string @@ -384,11 +388,14 @@ func CreateTaskForRunner(ctx context.Context, runner *Runner) (*Task, bool, erro job.Status = StatusRunning task := &Task{ - JobID: job.ID, - Attempt: job.Attempt, - RunnerID: runner.ID, - Started: now, - Status: StatusRunning, + JobID: job.ID, + Attempt: job.Attempt, + RunnerID: runner.ID, + Started: now, + Status: StatusRunning, + RepoID: job.RepoID, + OwnerID: job.OwnerID, + CommitSHA: job.CommitSHA, } if err := task.GenerateToken(); err != nil { return nil, false, err diff --git a/models/bots/task_list.go b/models/bots/task_list.go index 920d7928b3..9a0a92c6a7 100644 --- a/models/bots/task_list.go +++ b/models/bots/task_list.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/timeutil" + "xorm.io/builder" ) @@ -57,6 +58,9 @@ func (tasks TaskList) LoadAttributes(ctx context.Context) error { type FindTaskOptions struct { db.ListOptions + RepoID int64 + OwnerID int64 + CommitSHA string Status Status UpdatedBefore timeutil.TimeStamp StartedBefore timeutil.TimeStamp @@ -66,6 +70,15 @@ type FindTaskOptions struct { func (opts FindTaskOptions) toConds() builder.Cond { cond := builder.NewCond() + if opts.RepoID > 0 { + cond = cond.And(builder.Eq{"repo_id": opts.RepoID}) + } + if opts.OwnerID > 0 { + cond = cond.And(builder.Eq{"owner_id": opts.OwnerID}) + } + if opts.CommitSHA != "" { + cond = cond.And(builder.Eq{"commit_sha": opts.CommitSHA}) + } if opts.Status > StatusUnknown { cond = cond.And(builder.Eq{"status": opts.Status}) } diff --git a/models/migrations/v-dev.go b/models/migrations/v-dev.go index 6d46b97843..bfc90e6e9a 100644 --- a/models/migrations/v-dev.go +++ b/models/migrations/v-dev.go @@ -97,22 +97,32 @@ func addBotTables(x *xorm.Engine) error { type BotsRunIndex db.ResourceIndex type BotsTask struct { - ID int64 - JobID int64 - Attempt int64 - RunnerID int64 `xorm:"index"` - Result int32 - Status int `xorm:"index"` - Started timeutil.TimeStamp - Stopped timeutil.TimeStamp + ID int64 + JobID int64 + Attempt int64 + RunnerID int64 `xorm:"index"` + Result int32 + Status int `xorm:"index"` + Started timeutil.TimeStamp `xorm:"index"` + Stopped timeutil.TimeStamp + + RepoID int64 `xorm:"index"` + OwnerID int64 `xorm:"index"` + CommitSHA string `xorm:"index"` + + TokenHash string `xorm:"UNIQUE"` // sha256 of token + TokenSalt string + TokenLastEight string `xorm:"token_last_eight"` + LogFilename string // file name of log LogInStorage bool // read log from database or from storage LogLength int64 // lines count LogSize int64 // blob size LogIndexes *[]int64 `xorm:"BLOB"` // line number to offset - LogExpired bool - Created timeutil.TimeStamp `xorm:"created"` - Updated timeutil.TimeStamp `xorm:"updated"` + LogExpired bool // files that are too old will be deleted + + Created timeutil.TimeStamp `xorm:"created"` + Updated timeutil.TimeStamp `xorm:"updated index"` } type BotsTaskStep struct {