feat: models for runner task

This commit is contained in:
Jason Song
2022-10-08 15:16:52 +08:00
parent 5093d6b48e
commit 905bce6cb6
5 changed files with 189 additions and 0 deletions

47
models/bots/task_log.go Normal file
View 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
}