mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 03:25:11 +01:00 
			
		
		
		
	feat: models for runner task
This commit is contained in:
		
							parent
							
								
									5093d6b48e
								
							
						
					
					
						commit
						905bce6cb6
					
				
							
								
								
									
										43
									
								
								models/bots/run.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								models/bots/run.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,43 @@ | ||||
| // Copyright 2022 The Gitea Authors. All rights reserved. | ||||
| // Use of this source code is governed by a MIT-style | ||||
| // license that can be found in the LICENSE file. | ||||
| 
 | ||||
| package bots | ||||
| 
 | ||||
| import ( | ||||
| 	"code.gitea.io/gitea/core" | ||||
| 	"code.gitea.io/gitea/models/db" | ||||
| 	user_model "code.gitea.io/gitea/models/user" | ||||
| 	"code.gitea.io/gitea/models/webhook" | ||||
| 	"code.gitea.io/gitea/modules/timeutil" | ||||
| ) | ||||
| 
 | ||||
| // Run represents a run of a workflow file | ||||
| type Run struct { | ||||
| 	ID            int64 | ||||
| 	Name          string | ||||
| 	RepoID        int64  `xorm:"index unique(repo_workflow_number)"` | ||||
| 	WorkflowID    string `xorm:"index unique(repo_workflow_number)"` // the name of workflow file | ||||
| 	Number        int64  `xorm:"index unique(repo_workflow_number)"` // a unique number for each run of a particular workflow in a repository | ||||
| 	TriggerUserID int64 | ||||
| 	TriggerUser   *user_model.User `xorm:"-"` | ||||
| 	Ref           string | ||||
| 	CommitSHA     string | ||||
| 	Event         webhook.HookEventType | ||||
| 	Token         string           // token for this task | ||||
| 	Grant         string           // permissions for this task | ||||
| 	EventPayload  string           `xorm:"LONGTEXT"` | ||||
| 	Status        core.BuildStatus `xorm:"index"` | ||||
| 	StartTime     timeutil.TimeStamp | ||||
| 	EndTime       timeutil.TimeStamp | ||||
| 	Created       timeutil.TimeStamp `xorm:"created"` | ||||
| 	Updated       timeutil.TimeStamp `xorm:"updated"` | ||||
| } | ||||
| 
 | ||||
| func init() { | ||||
| 	db.RegisterModel(new(Run)) | ||||
| } | ||||
| 
 | ||||
| func (Run) TableName() string { | ||||
| 	return "bots_run" | ||||
| } | ||||
							
								
								
									
										34
									
								
								models/bots/run_job.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								models/bots/run_job.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | ||||
| // Copyright 2022 The Gitea Authors. All rights reserved. | ||||
| // Use of this source code is governed by a MIT-style | ||||
| // license that can be found in the LICENSE file. | ||||
| 
 | ||||
| package bots | ||||
| 
 | ||||
| import ( | ||||
| 	"code.gitea.io/gitea/core" | ||||
| 	"code.gitea.io/gitea/models/db" | ||||
| 	"code.gitea.io/gitea/modules/timeutil" | ||||
| ) | ||||
| 
 | ||||
| // RunJob represents a job of a run | ||||
| type RunJob struct { | ||||
| 	ID              int64 | ||||
| 	RunID           int64 | ||||
| 	Name            string | ||||
| 	WorkflowPayload string           `xorm:"LONGTEXT"` | ||||
| 	Needs           []int64          `xorm:"JSON TEXT"` | ||||
| 	TaskID          int64            // the latest task of the job | ||||
| 	Status          core.BuildStatus `xorm:"index"` | ||||
| 	StartTime       timeutil.TimeStamp | ||||
| 	EndTime         timeutil.TimeStamp | ||||
| 	Created         timeutil.TimeStamp `xorm:"created"` | ||||
| 	Updated         timeutil.TimeStamp `xorm:"updated"` | ||||
| } | ||||
| 
 | ||||
| func init() { | ||||
| 	db.RegisterModel(new(RunJob)) | ||||
| } | ||||
| 
 | ||||
| func (RunJob) TableName() string { | ||||
| 	return "bots_run_job" | ||||
| } | ||||
							
								
								
									
										33
									
								
								models/bots/task.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								models/bots/task.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | ||||
| // Copyright 2022 The Gitea Authors. All rights reserved. | ||||
| // Use of this source code is governed by a MIT-style | ||||
| // license that can be found in the LICENSE file. | ||||
| 
 | ||||
| package bots | ||||
| 
 | ||||
| import ( | ||||
| 	"code.gitea.io/gitea/models/db" | ||||
| 	"code.gitea.io/gitea/modules/timeutil" | ||||
| ) | ||||
| 
 | ||||
| // Task represents a distribution of job | ||||
| type Task struct { | ||||
| 	ID        int64 | ||||
| 	JobID     int64 | ||||
| 	Attempt   int64 | ||||
| 	RunnerID  int64  `xorm:"index"` | ||||
| 	LogToFile bool   // read log from database or from storage | ||||
| 	LogUrl    string // url of the log file in storage | ||||
| 	Result    int64  // TODO: use runnerv1.Result | ||||
| 	Started   timeutil.TimeStamp | ||||
| 	Stopped   timeutil.TimeStamp | ||||
| 	Created   timeutil.TimeStamp `xorm:"created"` | ||||
| 	Updated   timeutil.TimeStamp `xorm:"updated"` | ||||
| } | ||||
| 
 | ||||
| func init() { | ||||
| 	db.RegisterModel(new(Task)) | ||||
| } | ||||
| 
 | ||||
| func (Task) TableName() string { | ||||
| 	return "bots_task" | ||||
| } | ||||
							
								
								
									
										47
									
								
								models/bots/task_log.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								models/bots/task_log.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,47 @@ | ||||
| // Copyright 2022 The Gitea Authors. All rights reserved. | ||||
| // Use of this source code is governed by a MIT-style | ||||
| // license that can be found in the LICENSE file. | ||||
| 
 | ||||
| package bots | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 
 | ||||
| 	"code.gitea.io/gitea/models/db" | ||||
| 	"code.gitea.io/gitea/modules/timeutil" | ||||
| ) | ||||
| 
 | ||||
| // TaskLog represents a task's log, every task has a standalone table | ||||
| type TaskLog struct { | ||||
| 	ID      int64 | ||||
| 	Content string             `xorm:"BINARY"` | ||||
| 	Created timeutil.TimeStamp `xorm:"created"` | ||||
| } | ||||
| 
 | ||||
| func init() { | ||||
| 	db.RegisterModel(new(TaskLog)) | ||||
| } | ||||
| 
 | ||||
| func GetTaskLogTableName(taskID int64) string { | ||||
| 	return fmt.Sprintf("bots_task_log_%d", taskID) | ||||
| } | ||||
| 
 | ||||
| // CreateTaskLog table for a build | ||||
| func CreateTaskLog(buildID int64) error { | ||||
| 	return db.GetEngine(db.DefaultContext). | ||||
| 		Table(GetBuildLogTableName(buildID)). | ||||
| 		Sync2(new(BuildLog)) | ||||
| } | ||||
| 
 | ||||
| func GetTaskLogs(taskID, index, length int64) (logs []*TaskLog, err error) { | ||||
| 	sess := db.GetEngine(db.DefaultContext).Table(GetBuildLogTableName(taskID)). | ||||
| 		Where("id>=?", index) | ||||
| 
 | ||||
| 	if length > 0 { | ||||
| 		sess.Limit(int(length)) | ||||
| 	} | ||||
| 
 | ||||
| 	err = sess.Find(&logs) | ||||
| 
 | ||||
| 	return | ||||
| } | ||||
							
								
								
									
										32
									
								
								models/bots/task_step.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								models/bots/task_step.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | ||||
| // Copyright 2022 The Gitea Authors. All rights reserved. | ||||
| // Use of this source code is governed by a MIT-style | ||||
| // license that can be found in the LICENSE file. | ||||
| 
 | ||||
| package bots | ||||
| 
 | ||||
| import ( | ||||
| 	"code.gitea.io/gitea/models/db" | ||||
| 	"code.gitea.io/gitea/modules/timeutil" | ||||
| ) | ||||
| 
 | ||||
| // TaskStep represents a step of Task | ||||
| type TaskStep struct { | ||||
| 	ID        int64 | ||||
| 	TaskID    int64 | ||||
| 	Number    int64 | ||||
| 	Result    int64 // TODO: use runnerv1.Result | ||||
| 	LogIndex  int64 | ||||
| 	LogLength int64 | ||||
| 	Started   timeutil.TimeStamp | ||||
| 	Stopped   timeutil.TimeStamp | ||||
| 	Created   timeutil.TimeStamp `xorm:"created"` | ||||
| 	Updated   timeutil.TimeStamp `xorm:"updated"` | ||||
| } | ||||
| 
 | ||||
| func (TaskStep) TableName() string { | ||||
| 	return "bots_task_step" | ||||
| } | ||||
| 
 | ||||
| func init() { | ||||
| 	db.RegisterModel(new(TaskStep)) | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user