/
crontab.go
111 lines (95 loc) · 2.35 KB
/
crontab.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package model
import (
"database/sql/driver"
"encoding/json"
"errors"
"github.com/jinzhu/gorm"
)
type CrontabTask struct {
gorm.Model
Name string `gorm:"unique;not null"`
Command string
Depends DependsTasks `gorm:"type:TEXT"`
PipeCommands PipeComamnds `gorm:"type:TEXT"`
State int // 0/1/2
Args string
Create int64
LastCostTime int64
LastExecTime int64
LastExitStatus string
Timeout int64
NumberProcess int32
TimerCounter int32
UnexpectedExitMail bool
UnexpectedExitApi bool
Sync bool // 脚本是否同步执行
MailTo string
ApiTo string
MaxConcurrent int // 脚本最大并发量
OpTimeout string // email/kill/email_and_kill/ignore/api
C CrontabArgs `gorm:"type:TEXT"`
}
type DependsTasks []DependsTask
func (d *DependsTasks) Scan(v interface{}) error {
switch val := v.(type) {
case string:
return json.Unmarshal([]byte(val), d)
case []byte:
return json.Unmarshal(val, d)
default:
return errors.New("not support")
}
}
func (d DependsTasks) Value() (driver.Value, error) {
bts, err := json.Marshal(d)
return string(bts), err
}
type CrontabArgs struct {
Weekday string
Month string
Day string
Hour string
Minute string
}
func (c *CrontabArgs) Scan(v interface{}) error {
switch val := v.(type) {
case string:
return json.Unmarshal([]byte(val), c)
case []byte:
return json.Unmarshal(val, c)
default:
return errors.New("not support")
}
}
func (c CrontabArgs) Value() (driver.Value, error) {
bts, err := json.Marshal(c)
return string(bts), err
}
type DependsTask struct {
Name string
Dest string
From string
TaskId uint
Id string `json:"-"`
TaskEntityId string `json:"-"`
Command string
Args string
Timeout int64
Err string `json:"-"`
LogContent []byte `json:"-"`
}
type PipeComamnds [][]string
func (p *PipeComamnds) Scan(v interface{}) error {
switch val := v.(type) {
case string:
return json.Unmarshal([]byte(val), p)
case []byte:
return json.Unmarshal(val, p)
default:
return errors.New("not support")
}
}
func (p PipeComamnds) Value() (driver.Value, error) {
bts, err := json.Marshal(p)
return string(bts), err
}