V1.2
1、新增服务器资源添加 (新增数据表pp_task_server) 2、新增远程服务器任务执行 3、删除邮件通知功能(pp_task删除两个有关字段)
This commit is contained in:
@@ -30,9 +30,7 @@ func Init() {
|
||||
dsn = dsn + "&loc=" + url.QueryEscape(timezone)
|
||||
}
|
||||
orm.RegisterDataBase("default", "mysql", dsn)
|
||||
|
||||
// orm.RegisterModel(new(User), new(Task), new(TaskGroup), new(TaskLog))
|
||||
orm.RegisterModel(new(User), new(Task), new(TaskGroup), new(TaskLog))
|
||||
orm.RegisterModel(new(User), new(Task), new(TaskGroup), new(TaskLog),new(TaskServer))
|
||||
|
||||
if beego.AppConfig.String("runmode") == "dev" {
|
||||
orm.Debug = true
|
||||
|
||||
@@ -22,6 +22,7 @@ const (
|
||||
type Task struct {
|
||||
Id int
|
||||
UserId int
|
||||
ServerId int
|
||||
GroupId int
|
||||
TaskName string
|
||||
TaskType int
|
||||
@@ -30,8 +31,6 @@ type Task struct {
|
||||
Concurrent int
|
||||
Command string
|
||||
Status int
|
||||
Notify int
|
||||
NotifyEmail string
|
||||
Timeout int
|
||||
ExecuteTimes int
|
||||
PrevTime int64
|
||||
|
||||
@@ -60,9 +60,7 @@ func TaskGroupDelById(id int) error {
|
||||
|
||||
func TaskGroupGetList(page, pageSize int) ([]*TaskGroup, int64) {
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
list := make([]*TaskGroup, 0)
|
||||
|
||||
query := orm.NewOrm().QueryTable(TableName("task_group"))
|
||||
total, _ := query.Count()
|
||||
query.OrderBy("-id").Limit(pageSize, offset).All(&list)
|
||||
|
||||
87
models/task_server.go
Normal file
87
models/task_server.go
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* @Author: haodaquan
|
||||
* @Date: 2017-08-16 12:22:37
|
||||
* @Last Modified by: haodaquan
|
||||
* @Last Modified time: 2017-08-16 12:22:55
|
||||
*/
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
type TaskServer struct {
|
||||
Id int
|
||||
ServerName string
|
||||
ServerIp string
|
||||
Port int
|
||||
Password string
|
||||
PrivateKeySrc string
|
||||
PublicKeySrc string
|
||||
Type int
|
||||
Detail string
|
||||
CreateTime int64
|
||||
UpdateTime int64
|
||||
Status int
|
||||
}
|
||||
|
||||
func (t *TaskServer) TableName() string {
|
||||
return TableName("task_server")
|
||||
}
|
||||
|
||||
func (t *TaskServer) Update(fields ...string) error {
|
||||
if t.ServerName == "" {
|
||||
return fmt.Errorf("服务器名不能为空")
|
||||
}
|
||||
if t.ServerIp == "" {
|
||||
return fmt.Errorf("服务器IP不能为空")
|
||||
}
|
||||
|
||||
if t.Type == 0 && t.Password == "" {
|
||||
return fmt.Errorf("服务器密码不能为空")
|
||||
}
|
||||
|
||||
if t.Type == 1 && t.PrivateKeySrc == "" {
|
||||
return fmt.Errorf("私钥不能为空")
|
||||
}
|
||||
|
||||
if _, err := orm.NewOrm().Update(t, fields...); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TaskServerAdd(obj *TaskServer) (int64, error) {
|
||||
if obj.ServerName == "" {
|
||||
return 0, fmt.Errorf("服务器名不能为空")
|
||||
}
|
||||
return orm.NewOrm().Insert(obj)
|
||||
}
|
||||
|
||||
func TaskServerGetById(id int) (*TaskServer, error) {
|
||||
obj := &TaskServer{
|
||||
Id: id,
|
||||
}
|
||||
err := orm.NewOrm().Read(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
func TaskServerDelById(id int) error {
|
||||
_, err := orm.NewOrm().QueryTable(TableName("task_server")).Filter("id", id).Delete()
|
||||
return err
|
||||
}
|
||||
|
||||
func TaskServerGetList(page, pageSize int) ([]*TaskServer, int64) {
|
||||
offset := (page - 1) * pageSize
|
||||
list := make([]*TaskServer, 0)
|
||||
query := orm.NewOrm().QueryTable(TableName("task_server"))
|
||||
total, _ := query.Count()
|
||||
query.OrderBy("-id").Limit(pageSize, offset).All(&list)
|
||||
|
||||
return list, total
|
||||
}
|
||||
Reference in New Issue
Block a user