task

package
v0.0.0-...-73f8a9c Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// todo, del useless status; 从写只使用了很少的状态
	//顺序递进
	CheckFailed Status = "checkFailed"
	CheckPass          = "checkPass"
	ReviewPass         = "reviewPass"
	DBAPass            = "dbaPass"
	ExecWait           = "execWait"
	Executing          = "executing"
	ExecFailed         = "execFailed"
	ExecSuccess        = "execSuccess"

	//终止状态
	Reject     Status = "reject"
	Cancel            = "cancel"
	ExecCancel        = "execCancel"

	//子项状态
	SkipExec Status = "skipExec"
)
View Source
const (
	ItemFailed      ItemStatus = "failed"
	ItemCheckFailed            = "check_failed"
	ItemCheckPass              = "check_pass"
	ItemSuccess                = "success"
	ItemSkipped                = "skipped"

	ItemNoBackup        ItemStatus = "no_backup"
	ItemBackupSuccess              = "backup_success"
	ItemBackupFailed               = "backup_failed"
	ItemRollBackFailed             = "roll_backup_failed"
	ItemRollBackSuccess            = "roll_backup_success"
)
View Source
const (
	DML       TaskType = "DML"
	DDLCreate          = "CREATE"
	DDLUpdate          = "UPDATE"
)
View Source
const (
	EditItem Action = "editItem"
	DelItem         = "delItem"
	DoCancel        = "cancel"
	SkipAt          = "skipAt"
	BeginAt         = "beginAt"
	DoExec          = "exec"
	DoReject        = "reject"
	Resubmit        = "resubmit"
)
View Source
const (
	NUL = ""
)

Variables

View Source
var AuthTool authTools

Functions

func AddTask

func AddTask(task *OwlTask) (int64, error)

func BackupAndExec

func BackupAndExec(db *sql.DB, item *OwlExecItem, taskType string) error

backup, exec, update status

func CheckTaskType

func CheckTaskType(task *OwlTask) error

func Exec

func Exec(paramTask, dbTask *OwlTask) error

func ExecTask

func ExecTask(paramTask, dbTask *OwlTask) error

func ExecTaskDirectly

func ExecTaskDirectly(paramTask, dbTask *OwlTask) error

exec and update status exec from head, skip at some one, or begin at some one

func GetTableInfo

func GetTableInfo(req *SqlParam) (string, error)

func GetTypeName

func GetTypeName(taskType string) string

func IsDba

func IsDba(userName string) (isDba bool, err error)

func Rollback

func Rollback(req *SqlParam) error

原sql,判断是删还是改 查出来备份数据 如果是删,直接插入回原来的表 如果是改,判断哪些字段,根据主键,把原来的字段set回去。 最后更改备份状态

func SetAuthTools

func SetAuthTools(impl authTools)

func SetBackupDao

func SetBackupDao(impl BackupDao)

func SetChecker

func SetChecker(impl sqlChecker)

func SetDbTools

func SetDbTools(impl dbTools)

func SetSubTaskDao

func SetSubTaskDao(impl SubTaskDao)

func SetTaskDao

func SetTaskDao(impl TaskDao)

func StatusName

func StatusName(status Status) string

func UpdateTask

func UpdateTask(task *OwlTask) error

Types

type Action

type Action = string

type BackupDao

type BackupDao interface {
	AddBackup(backup *OwlBackup) (int64, error)
	UpdateBackup(backup *OwlBackup) error
	GetBackupInfoById(id int64) (*OwlBackup, error)
}

type BackupDataResp

type BackupDataResp struct {
	DataItems [][]string `json:"data_items"`
	Index     []int      `json:"index"`
	Columns   []string   `json:"columns"`
}

func ListRollbackData

func ListRollbackData(req *SqlParam) (*BackupDataResp, error)

ListRollbackData ...

type DBInfo

type DBInfo struct {
	DB        *sql.DB
	DefaultDB *sql.DB
	DBName    string
}

func (*DBInfo) CloseConn

func (db *DBInfo) CloseConn()

type EditAuth

type EditAuth struct {
	SubmitReviewEnable        bool `json:"submit_review_enable"`
	SysReviewEnable           bool `json:"sys_review_enable"`
	WithdrawEnable            bool `json:"withdraw_enable"`
	TurnDownEnable            bool `json:"turn_down_enable"`
	SubmitExecEnable          bool `json:"submit_exec_enable"`
	ExecEnable                bool `json:"exec_enable"`
	TurnDownExecEnable        bool `json:"turn_down_exec_enable"`
	ReviewEnable              bool `json:"review_enable"`
	ReviewPassEnable          bool `json:"review_pass_enable"`
	CreatorSubmitReviewEnable bool `json:"creator_submit_review_enable"`
	CreatorTurnDownEnable     bool `json:"creator_turn_down_enable"`
}

func GetTaskOperateAuth

func GetTaskOperateAuth(detail, isCreator, isReviewer, isDba bool, task *OwlTask) *EditAuth

GetTaskOpAbility根据task状态,获取角色的可操作类型

type ItemStatus

type ItemStatus = string

func ExecStatus

func ExecStatus() []ItemStatus

func HistoryStatus

func HistoryStatus() []ItemStatus

func SubmitStatus

func SubmitStatus() []ItemStatus

type OwlAccount

type OwlAccount struct {
	ID       uint64 `json:"id" gorm:"column:id"`
	Username string `json:"username" gorm:"column:username"`
	Passwd   string `json:"passwd" gorm:"column:passwd"`
	Dbtype   int64  `json:"dbtype" gorm:"column:dbtype"`
}

type OwlBackup

type OwlBackup struct {
	ID           int64  `json:"id" gorm:"column:id"`
	Data         string `json:"data" gorm:"column:data"`
	Ct           int64  `json:"ct" gorm:"column:ct"`
	RollbackTime int64  `json:"rollback_time" gorm:"column:rollback_time"`
	RollbackUser string `json:"rollback_user" gorm:"column:rollback_user"`
	IsRolledBack int    `json:"is_rolled_back" gorm:"column:is_rolled_back"`
}

type OwlExecItem

type OwlExecItem struct {
	ID           int64  `json:"id" gorm:"column:id"`
	TaskID       int64  `json:"task_id" gorm:"column:task_id"`
	SubtaskID    int64  `json:"subtask_id" gorm:"column:subtask_id"`
	SQLContent   string `json:"sql_content" gorm:"column:sql_content"`
	Remark       string `json:"remark" gorm:"column:remark"`
	AffectRows   int    `json:"affect_rows" gorm:"column:affect_rows"`
	RuleComments string `json:"rule_comments" gorm:"column:rule_comments"`
	Status       string `json:"status" gorm:"column:status"`
	ExecInfo     string `json:"exec_info" gorm:"column:exec_info"`
	BackupInfo   string `json:"backup_info" gorm:"column:backup_info"`
	BackupStatus string `json:"backup_status" gorm:"column:backup_status"`
	BackupID     int64  `json:"backup_id" gorm:"column:backup_id"`

	Ut int64 `json:"ut" gorm:"column:ut"`
	Et int64 `json:"et" gorm:"column:et"`

	DBName      string `json:"db_name" gorm:"-"`
	ClusterName string `json:"cluster_name" gorm:"-"`
	TaskType    string `json:"task_type" gorm:"-"`
}

type OwlSubtask

type OwlSubtask struct {
	ID          int64  `json:"id" gorm:"column:id"`
	TaskID      int64  `json:"task_id" gorm:"column:task_id"`
	TaskType    string `json:"task_type" gorm:"column:task_type"`
	DbName      string `json:"db_name" gorm:"column:db_name"`
	ClusterName string `json:"cluster_name" gorm:"column:cluster_name"`

	ExecItems []OwlExecItem `json:"exec_items" gorm:"-"`
}

type OwlTask

type OwlTask struct {
	ID            int64  `json:"id" gorm:"column:id"`
	Name          string `json:"name" gorm:"column:name"`
	Status        string `json:"status" gorm:"column:status"`
	Creator       string `json:"creator" gorm:"column:creator"`
	Reviewer      string `json:"reviewer" gorm:"column:reviewer"`
	Executor      string `json:"executor" gorm:"column:executor"`
	ExecInfo      string `json:"exec_info" gorm:"column:exec_info"`
	RejectContent string `json:"reject_content" gorm:"column:reject_content"`
	Ct            int64  `json:"ct" gorm:"column:ct"`
	Ut            int64  `json:"ut" gorm:"column:ut"`
	Et            int64  `json:"et" gorm:"column:et"`
	Ft            int64  `json:"ft" gorm:"column:ft"`

	SubTasks  []OwlSubtask  `json:"sub_tasks" gorm:"-"`
	ExecItems []OwlExecItem `json:"exec_items" gorm:"-"`
	ExecItem  *OwlExecItem  `json:"exec_item" gorm:"-"`
	EditAuth  *EditAuth     `json:"edit_auth" gorm:"-"`

	StatusName string `json:"status_name" gorm:"-"`
	Action     Action `json:"action" gorm:"-"`
}

func GetExecWaitTask

func GetExecWaitTask() ([]OwlTask, int64, error)

func GetTask

func GetTask(id int64, operator string) (*OwlTask, error)

func ListTask

func ListTask(pageInfo request.SortPageInfo, status []ItemStatus) ([]OwlTask, int64, error)

type ReadResult

type ReadResult struct {
	DataItems interface{} `json:"data_items"`
	Columns   []string    `json:"columns"`
}

func ReadData

func ReadData(req *SqlParam) (*ReadResult, error)

ListRollbackData ...

type SqlParam

type SqlParam struct {
	DBName      string `json:"db_name"`
	ClusterName string `json:"cluster_name"`
	TableName   string `json:"table_name"`
	Sql         string `json:"sql"`
	BackupId    int64  `json:"backup_id"`
	Executor    string `json:"executor"`
}

type Status

type Status = string

type SubTaskDao

type SubTaskDao interface {
	UpdateItem(item *OwlExecItem) error
	DelItem(item *OwlExecItem) error
	UpdateItemByBackupId(item *OwlExecItem) error
}

type TaskDao

type TaskDao interface {
	AddTask(task *OwlTask) (int64, error)
	UpdateTask(task *OwlTask) error
	ListTask(pageInfo request.SortPageInfo, isDBA bool, status []ItemStatus) ([]OwlTask, int64, error)
	GetTask(id int64) (*OwlTask, error)
	GetExecWaitTask() ([]OwlTask, int64, error)
}

type TaskType

type TaskType = string

Jump to

Keyboard shortcuts

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