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

chore: add ids to task

This commit is contained in:
Jason Song 2022-11-11 16:52:22 +08:00
parent 381d06729b
commit e19f2c8c44
3 changed files with 48 additions and 18 deletions

View File

@ -22,13 +22,13 @@ import (
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "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" gouuid "github.com/google/uuid"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
"github.com/nektos/act/pkg/jobparser" "github.com/nektos/act/pkg/jobparser"
"google.golang.org/protobuf/types/known/timestamppb" "google.golang.org/protobuf/types/known/timestamppb"
"xorm.io/builder"
) )
// Task represents a distribution of job // Task represents a distribution of job
@ -44,6 +44,10 @@ type Task struct {
Started timeutil.TimeStamp `xorm:"index"` Started timeutil.TimeStamp `xorm:"index"`
Stopped timeutil.TimeStamp Stopped timeutil.TimeStamp
RepoID int64 `xorm:"index"`
OwnerID int64 `xorm:"index"`
CommitSHA string `xorm:"index"`
Token string `xorm:"-"` Token string `xorm:"-"`
TokenHash string `xorm:"UNIQUE"` // sha256 of token TokenHash string `xorm:"UNIQUE"` // sha256 of token
TokenSalt string TokenSalt string
@ -389,6 +393,9 @@ func CreateTaskForRunner(ctx context.Context, runner *Runner) (*Task, bool, erro
RunnerID: runner.ID, RunnerID: runner.ID,
Started: now, Started: now,
Status: StatusRunning, Status: StatusRunning,
RepoID: job.RepoID,
OwnerID: job.OwnerID,
CommitSHA: job.CommitSHA,
} }
if err := task.GenerateToken(); err != nil { if err := task.GenerateToken(); err != nil {
return nil, false, err return nil, false, err

View File

@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"xorm.io/builder" "xorm.io/builder"
) )
@ -57,6 +58,9 @@ func (tasks TaskList) LoadAttributes(ctx context.Context) error {
type FindTaskOptions struct { type FindTaskOptions struct {
db.ListOptions db.ListOptions
RepoID int64
OwnerID int64
CommitSHA string
Status Status Status Status
UpdatedBefore timeutil.TimeStamp UpdatedBefore timeutil.TimeStamp
StartedBefore timeutil.TimeStamp StartedBefore timeutil.TimeStamp
@ -66,6 +70,15 @@ type FindTaskOptions struct {
func (opts FindTaskOptions) toConds() builder.Cond { func (opts FindTaskOptions) toConds() builder.Cond {
cond := builder.NewCond() 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 { if opts.Status > StatusUnknown {
cond = cond.And(builder.Eq{"status": opts.Status}) cond = cond.And(builder.Eq{"status": opts.Status})
} }

View File

@ -103,16 +103,26 @@ func addBotTables(x *xorm.Engine) error {
RunnerID int64 `xorm:"index"` RunnerID int64 `xorm:"index"`
Result int32 Result int32
Status int `xorm:"index"` Status int `xorm:"index"`
Started timeutil.TimeStamp Started timeutil.TimeStamp `xorm:"index"`
Stopped timeutil.TimeStamp 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 LogFilename string // file name of log
LogInStorage bool // read log from database or from storage LogInStorage bool // read log from database or from storage
LogLength int64 // lines count LogLength int64 // lines count
LogSize int64 // blob size LogSize int64 // blob size
LogIndexes *[]int64 `xorm:"BLOB"` // line number to offset LogIndexes *[]int64 `xorm:"BLOB"` // line number to offset
LogExpired bool LogExpired bool // files that are too old will be deleted
Created timeutil.TimeStamp `xorm:"created"` Created timeutil.TimeStamp `xorm:"created"`
Updated timeutil.TimeStamp `xorm:"updated"` Updated timeutil.TimeStamp `xorm:"updated index"`
} }
type BotsTaskStep struct { type BotsTaskStep struct {