chore(runner): add soft deleted field

This commit is contained in:
Bo-Yi Wu
2022-10-12 14:37:57 +08:00
committed by Jason Song
parent 9648482ed6
commit 699f5c5a06
8 changed files with 14 additions and 19 deletions

View File

@@ -226,7 +226,7 @@ func GetBuildByRepoAndIndex(repoID, index int64) (*Build, error) {
}
// AssignBuildToRunner assign a build to a runner
func AssignBuildToRunner(buildID int64, runnerID int64) error {
func AssignBuildToRunner(buildID, runnerID int64) error {
cnt, err := db.GetEngine(db.DefaultContext).
Where("runner_id=0").
And("id=?", buildID).

View File

@@ -81,15 +81,15 @@ func (r *Run) LoadAttributes(ctx context.Context) error {
// InsertRun inserts a bot run
func InsertRun(run *Run, jobs []*jobparser.SingleWorkflow) error {
var groupId int64
var groupID int64
{
// tricky way to get resource group id
h := fnv.New64()
_, _ = h.Write([]byte(fmt.Sprintf("%d_%s", run.RepoID, run.WorkflowID)))
groupId = int64(h.Sum64())
groupID = int64(h.Sum64())
}
index, err := db.GetNextResourceIndex("bots_run_index", groupId)
index, err := db.GetNextResourceIndex("bots_run_index", groupID)
if err != nil {
return err
}

View File

@@ -54,11 +54,8 @@ func (job *RunJob) LoadAttributes(ctx context.Context) error {
}
job.Run = run
}
if err := job.Run.LoadAttributes(ctx); err != nil {
return err
}
return nil
return job.Run.LoadAttributes(ctx)
}
// ErrRunJobNotExist represents an error for bot run job not exist

View File

@@ -55,6 +55,8 @@ type Runner struct {
LastOnline timeutil.TimeStamp `xorm:"index"`
Created timeutil.TimeStamp `xorm:"created"`
Updated timeutil.TimeStamp `xorm:"updated"`
Deleted timeutil.TimeStamp `xorm:"deleted"`
}
func (Runner) TableName() string {

View File

@@ -36,8 +36,9 @@ type RunnerToken struct {
Repo *repo_model.Repository `xorm:"-"`
IsActive bool
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
Created timeutil.TimeStamp `xorm:"created"`
Updated timeutil.TimeStamp `xorm:"updated"`
Deleted timeutil.TimeStamp `xorm:"deleted"`
}
func (RunnerToken) TableName() string {

View File

@@ -21,7 +21,7 @@ type Task struct {
Attempt int64
RunnerID int64 `xorm:"index"`
LogToFile bool // read log from database or from storage
LogUrl string // url of the log file in storage
LogURL string // url of the log file in storage
Result runnerv1.Result
Started timeutil.TimeStamp
Stopped timeutil.TimeStamp
@@ -50,11 +50,8 @@ func (task *Task) LoadAttributes(ctx context.Context) error {
}
task.Job = job
}
if err := task.Job.LoadAttributes(ctx); err != nil {
return err
}
return nil
return task.Job.LoadAttributes(ctx)
}
func CreateTask(runner *Runner) (*Task, bool, error) {
@@ -71,7 +68,7 @@ func CreateTask(runner *Runner) (*Task, bool, error) {
// TODO: a more efficient way to filter labels
var job *RunJob
labels := append(runner.AgentLabels, runner.CustomLabels...)
labels := append([]string{}, append(runner.AgentLabels, runner.CustomLabels...)...)
for _, v := range jobs {
if isSubset(labels, v.RunsOn) {
job = v