models

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ONLINE  = "online"
	OFFLINE = "offline"
	MASTER  = "master"
	WORKER  = "worker"
)
View Source
const (
	MODESHELL = "shell"
	MODEHTTP  = "http"
	MODEMAIL  = "mail"
	MODEHOOK  = "hook"
)
View Source
const DefaultTimeFormat = "2006-01-02 15:04:05"

Variables

View Source
var Engine *xorm.Engine

Functions

func Connection

func Connection() (*xorm.Engine, error)

func CreateLog

func CreateLog(model Model, uid string, operation string) error

创建用户操作日志

func GeneratePassword

func GeneratePassword(password string) ([]byte, error)

func Migrate

func Migrate() error

迁移数据库

func ValidatePassword

func ValidatePassword(password string, hashed []byte) (bool, error)

Types

type Log

type Log struct {
	Id        int64     `json:"id" xorm:"pk autoincr comment('ID') BIGINT(20)"`
	UserId    string    `json:"user_id" xorm:"not null comment('用户ID') index CHAR(36)"`
	Operation string    `json:"operation" xorm:"not null comment('操作') VARCHAR(255)"`
	Result    string    `json:"result" xorm:"null comment('结果') LONGTEXT(0)"`
	CreatedAt time.Time `json:"created_at" xorm:"not null comment('创建于') created DATETIME"`
}

func (*Log) MarshalJSON

func (log *Log) MarshalJSON() ([]byte, error)

Marshal struct to json

func (*Log) Store

func (log *Log) Store() error

保存日志

func (*Log) TableName

func (log *Log) TableName() string

定义日志表名称

type Model

type Model interface {
	Store() error
	Update() error
	ToString() (string, error)
}

模型接口

type Node

type Node struct {
	Id          string               `json:"id" xorm:"not null pk comment('用户ID') CHAR(36)"`
	Name        string               `json:"name" xorm:"not null comment('名称') VARCHAR(255)"`
	Host        string               `json:"host" xorm:"not null comment('主机地址') VARCHAR(255)"`
	Port        int                  `json:"port" xorm:"not null comment('端口') SMALLINT(5)"`
	Mode        string               `json:"mode" xorm:"not null comment('节点类型') CHAR(6)"`
	Status      string               `json:"status" xorm:"not null default('connected') comment('状态') VARCHAR(255)"` // 状态
	Version     string               `json:"version" xorm:"not null comment('版本') VARCHAR(255)"`                     // 版本
	Description string               `json:"description" xorm:"comment('描述') VARCHAR(255)"`                          // 描述信息
	CreatedAt   utils.Time           `json:"created_at" xorm:"not null created comment('创建于') DATETIME"`             // 创建于
	UpdatedAt   utils.Time           `json:"updated_at" xorm:"not null updated comment('更新于') DATETIME"`             // 更新于
	Pipelines   []*PipelineNodePivot `json:"pipelines" xorm:"-"`                                                     // 关联的流水线
}

func (*Node) CreateOrUpdate

func (node *Node) CreateOrUpdate() error

创建或更新节点

func (*Node) Offline

func (node *Node) Offline()

更新状态为离线

func (*Node) Online

func (node *Node) Online()

更新状态为在线

func (*Node) Store

func (node *Node) Store() error

创建节点

func (*Node) TableName

func (node *Node) TableName() string

定义模型的数据表名称

func (*Node) ToString

func (node *Node) ToString() (string, error)

序列化

func (*Node) Update

func (node *Node) Update() error

更新节点信息

type PasswordResets

type PasswordResets struct {
	Email     string    `xorm:"not null index VARCHAR(255)"`
	Token     string    `xorm:"not null VARCHAR(255)"`
	CreatedAt time.Time `xorm:"not null created comment('创建于') DATETIME"`
}

func (*PasswordResets) TableName

func (resets *PasswordResets) TableName() string

定义模型的数据表名称

type Pipeline

type Pipeline struct {
	Id           string               `json:"id" validate:"-" xorm:"not null pk comment('ID') CHAR(36)"`
	Name         string               `json:"name" validate:"required" xorm:"not null comment('名称') VARCHAR(255)"`
	Description  string               `json:"description" validate:"-" xorm:"not null comment('描述') VARCHAR(255)"`
	Spec         string               `json:"spec" validate:"required" xorm:"not null comment('定时器') CHAR(64)"`
	Status       int                  `json:"status" validate:"numeric" xorm:"not null default 0 comment('状态') TINYINT(1)"`
	Finished     string               `json:"finished" validate:"omitempty,uuid4" xorm:"null comment('成功时执行') CHAR(36)"`
	Failed       string               `json:"failed" validate:"omitempty,uuid4" xorm:"null comment('失败时执行') CHAR(36)"`
	Overlap      int                  `json:"overlap" validate:"numeric" xorm:"not null default 0 comment('重复执行') TINYINT(1)"`
	CreatedAt    utils.Time           `json:"created_at" validate:"-" xorm:"not null created comment('创建于') DATETIME"`
	UpdatedAt    utils.Time           `json:"updated_at" validate:"-" xorm:"not null updated comment('更新于') DATETIME"`
	Nodes        []string             `json:"nodes" xorm:"-"`
	Steps        []*PipelineTaskPivot `json:"steps" xorm:"-"`
	Expression   *cronexpr.Expression `json:"-" xorm:"-"`
	NextTime     time.Time            `json:"-" xorm:"-"`
	FinishedTask *Task                `json:"finished_task,omitempty" xorm:"-"`
	FailedTask   *Task                `json:"failed_task,omitempty" xorm:"-"`
}

Pipeline 流水线模型

func (*Pipeline) Build

func (pipeline *Pipeline) Build() (origin []byte, err error)

构造流水线数据结构

func (*Pipeline) Destroy

func (pipeline *Pipeline) Destroy() error

删除任务流水线

func (*Pipeline) Store

func (pipeline *Pipeline) Store() error

创建任务流水线

func (*Pipeline) TableName

func (pipeline *Pipeline) TableName() string

定义模型的数据表名称

func (*Pipeline) ToString

func (pipeline *Pipeline) ToString() (string, error)

序列化

func (*Pipeline) Update

func (pipeline *Pipeline) Update() error

更新任务流水线属性

type PipelineNodePivot

type PipelineNodePivot struct {
	Id         string     `json:"id" xorm:"not null pk comment('ID') CHAR(36)"`
	PipelineId string     `json:"pipeline_id" validate:"required,uuid4" xorm:"not null index comment('流水线ID') CHAR(36)"`
	NodeId     string     `json:"node_id" validate:"required,uuid4" xorm:"not null index comment('节点ID') CHAR(36)"`
	CreatedAt  utils.Time `json:"created_at" validate:"-" xorm:"not null created comment('创建于') DATETIME"`
	Pipeline   *Pipeline  `json:"pipeline" xorm:"-"`
}

func (*PipelineNodePivot) Destroy

func (pivot *PipelineNodePivot) Destroy() error

解除关联

func (*PipelineNodePivot) Store

func (pivot *PipelineNodePivot) Store() error

创建关联

func (*PipelineNodePivot) TableName

func (pivot *PipelineNodePivot) TableName() string

定义模型的数据表名称

type PipelineRecords

type PipelineRecords struct {
	Id         string         `json:"id" xorm:"not null pk comment('ID') CHAR(36)"`
	PipelineId string         `json:"pipeline_id" xorm:"not null comment('流水线ID') index CHAR(36)"`
	NodeId     string         `json:"node_id" xorm:"not null comment('节点ID') index CHAR(36)"`
	WorkerName string         `json:"worker_name" xorm:"not null comment('节点名称') VARCHAR(255)"`
	Spec       string         `json:"spec" xorm:"comment('定时器') CHAR(64)"`
	Status     int            `json:"status" xorm:"not null default 1 comment('状态') TINYINT(1)"`
	Duration   int64          `json:"duration" xorm:"not null comment('持续时间') INT(10)"`
	BeginWith  utils.Time     `json:"begin_with" xorm:"not null comment('开始于') DATETIME"`
	FinishWith utils.Time     `json:"finish_with" xorm:"not null comment('结束于') DATETIME"`
	CreatedAt  utils.Time     `json:"created_at" validate:"-" xorm:"not null created comment('创建于') DATETIME"`
	UpdatedAt  utils.Time     `json:"updated_at" validate:"-" xorm:"not null updated comment('更新于') DATETIME"`
	Steps      []*TaskRecords `json:"steps" xorm:"-"`
}

流水线调度记录模型

func (*PipelineRecords) Store added in v0.4.0

func (records *PipelineRecords) Store() error

保存流水线记录

func (*PipelineRecords) TableName

func (records *PipelineRecords) TableName() string

定义模型的数据表名称

func (*PipelineRecords) ToString added in v0.4.0

func (records *PipelineRecords) ToString() (string, error)

序列化

func (*PipelineRecords) Update added in v0.4.0

func (records *PipelineRecords) Update() error

更新记录

type PipelineTaskPivot

type PipelineTaskPivot struct {
	Id          string     `json:"id" xorm:"not null pk comment('ID') CHAR(36)"`
	PipelineId  string     `json:"pipeline_id" validate:"required,uuid4" xorm:"not null comment('ID') index CHAR(36)"`
	TaskId      string     `json:"task_id" validate:"required,uuid4" xorm:"not null comment('ID') index CHAR(36)"`
	Step        int        `json:"step" validate:"numeric" xorm:"not null comment('步骤') SMALLINT(5)"`
	Timeout     int        `json:"timeout" validate:"numeric" xorm:"not null default 0 comment('超时时间') INT(10)"`
	Interval    int        `json:"interval" validate:"numeric" xorm:"not null default 0 comment('间隔时间') INT(10)"`
	Retries     int        `json:"retries" validate:"numeric" xorm:"not null default 0 comment('重试次数') TINYINT(3)"`
	Directory   string     `json:"directory" validate:"omitempty" xorm:"null comment('工作目录') VARCHAR(255)"`
	User        string     `json:"user" validate:"omitempty" xorm:"null comment('运行用户') VARCHAR(255)"`
	Environment string     `json:"environment" validate:"omitempty" xorm:"null comment('环境变量') VARCHAR(255)"`
	Dependence  string     `json:"dependence" validate:"required" xorm:"not null default 'strong' comment('依赖') VARCHAR(255)"`
	CreatedAt   utils.Time `json:"created_at" validate:"-" xorm:"not null created comment('创建于') DATETIME"`
	UpdatedAt   utils.Time `json:"updated_at" validate:"-" xorm:"not null updated comment('更新于') DATETIME"`
	Task        *Task      `json:"task" validate:"-" xorm:"-"`
}

func (*PipelineTaskPivot) Destroy

func (pivot *PipelineTaskPivot) Destroy() error

Delete a pipeline relation

func (*PipelineTaskPivot) Store

func (pivot *PipelineTaskPivot) Store() error

创建流水线和任务的关联关系

func (*PipelineTaskPivot) TableName

func (pivot *PipelineTaskPivot) TableName() string

定义模型的数据表名称

func (*PipelineTaskPivot) ToString

func (pivot *PipelineTaskPivot) ToString() (string, error)

序列化

func (*PipelineTaskPivot) Update

func (pivot *PipelineTaskPivot) Update() error

更新中间表

type Result added in v0.4.0

type Result struct {
	Pipeline *PipelineRecords // 流水线执行记录
	Steps    []*TaskRecords   // 流水线中任务执行记录
}

流水线执行结果

type Seeder

type Seeder interface {
	Seed() error
}

用于填充系统默认数据的接口

type Task

type Task struct {
	Id          string     `json:"id" validate:"-" xorm:"not null pk comment('用户ID') CHAR(36)"`
	Name        string     `json:"name" validate:"required" xorm:"not null comment('名称') VARCHAR(255)"`
	Mode        string     `json:"mode" validate:"required" xorm:"not null default('shell') comment('任务模式') VARCHAR(32)"`
	Url         string     `json:"url" validate:"omitempty" xorm:"null comment('请求URL') VARCHAR(255)"`
	Method      string     `json:"method" validate:"omitempty" xorm:"null comment('任务模式') VARCHAR(255)"`
	Content     string     `json:"content" validate:"omitempty" xorm:"null comment('内容') TEXT"`
	Description string     `json:"description" validate:"-" xorm:"null comment('描述') VARCHAR(255)"`
	CreatedAt   utils.Time `json:"created_at" validate:"-" xorm:"not null created comment('创建于') DATETIME"`
	UpdatedAt   utils.Time `json:"updated_at" validate:"-" xorm:"not null updated comment('更新于') DATETIME"`
}

Task 任务模型

func (*Task) Destroy

func (task *Task) Destroy() error

删除任务

func (*Task) Store

func (task *Task) Store() error

创建任务

func (*Task) TableName

func (task *Task) TableName() string

定义模型的数据表名称

func (*Task) ToString

func (task *Task) ToString() (string, error)

序列化

func (*Task) Update

func (task *Task) Update() error

更新任务

type TaskRecords

type TaskRecords struct {
	Id               int64      `json:"id" xorm:"pk autoincr comment('ID') BIGINT(20)"`
	PipelineRecordId string     `json:"pipeline_record_id" xorm:"not null comment('流水线记录ID') index CHAR(36)"`
	TaskId           string     `json:"task_id" xorm:"not null comment('任务ID') index CHAR(36)"`
	NodeId           string     `json:"node_id" xorm:"not null comment('节点ID') index CHAR(36)"`
	TaskName         string     `json:"task_name" xorm:"not null comment('任务名称') VARCHAR(255)"`
	WorkerName       string     `json:"worker_name" xorm:"not null comment('节点名称') VARCHAR(255)"`
	Content          string     `json:"content" xorm:"not null comment('执行内容') TEXT"`
	Mode             string     `json:"mode" xorm:"not null comment('执行方式') VARCHAR(255)"`
	Timeout          int        `json:"timeout" xorm:"not null default 0 comment('超时时间') INT(10)"`
	Retries          int        `json:"retries" xorm:"not null default 0 comment('重试次数') TINYINT(3)"`
	Status           string     `json:"status" xorm:"not null default 'finished' comment('状态') VARCHAR(255)"`
	Result           string     `json:"result" xorm:"not null comment('执行结果') TEXT"`
	Duration         int64      `json:"duration" xorm:"not null comment('持续时间') INT(10)"`
	BeginWith        utils.Time `json:"begin_with" xorm:"not null comment('开始于') DATETIME"`
	FinishWith       utils.Time `json:"finish_with" xorm:"not null comment('结束于') DATETIME"`
	CreatedAt        utils.Time `json:"created_at" xorm:"not null comment('创建于') DATETIME"`
}

func (*TaskRecords) Store added in v0.4.0

func (records *TaskRecords) Store() error

保存流水线记录

func (*TaskRecords) TableName

func (records *TaskRecords) TableName() string

定义模型的数据表名称

func (*TaskRecords) ToString added in v0.4.0

func (records *TaskRecords) ToString() (string, error)

序列化

func (*TaskRecords) Update added in v0.4.0

func (records *TaskRecords) Update() error

更新记录

type User

type User struct {
	Id        string     `json:"id" xorm:"not null pk comment('用户ID') CHAR(36)"`
	Name      string     `json:"name" xorm:"not null comment('姓名') VARCHAR(255)"`
	Email     string     `json:"email" xorm:"not null comment('邮箱') unique VARCHAR(255)"`
	Password  string     `json:"-" xorm:"not null comment('密码') VARCHAR(255)"`
	Manager   bool       `json:"manager" xorm:"not null default 0 comment('管理员') TINYINT(1)"`
	CreatedAt utils.Time `json:"created_at" xorm:"not null created comment('创建于') DATETIME"`
	UpdatedAt utils.Time `json:"updated_at" xorm:"not null updated comment('更新于') DATETIME"`
}

func (*User) ModifyEmail

func (user *User) ModifyEmail(email string) (*User, error)

func (*User) Save

func (user *User) Save() error

func (*User) Store

func (user *User) Store() error

func (*User) TableName

func (user *User) TableName() string

Define table name

func (*User) ToString

func (user *User) ToString() (string, error)

序列化

func (*User) Update

func (user *User) Update() error

更新用户信息

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL