Skip to content

Commit 011b10f

Browse files
authored
Merge pull request #1128 from trheyi/main
Implement job management functionality and update job model
2 parents b5ef9b7 + 38f86aa commit 011b10f

File tree

11 files changed

+799
-158
lines changed

11 files changed

+799
-158
lines changed

data/bindata.go

Lines changed: 139 additions & 139 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

job/data.go

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package job
2+
3+
import (
4+
"github.com/yaoapp/gou/model"
5+
"github.com/yaoapp/kun/maps"
6+
)
7+
8+
// ========================
9+
// Jobs methods
10+
// ========================
11+
12+
// ListJobs list jobs
13+
func ListJobs(param model.QueryParam, page int, pagesize int) (maps.MapStrAny, error) {
14+
return nil, nil
15+
}
16+
17+
// GetActiveJobs get active jobs
18+
func GetActiveJobs() ([]*Job, error) {
19+
return nil, nil
20+
}
21+
22+
// CountJobs count jobs
23+
func CountJobs(param model.QueryParam) (int, error) {
24+
return 0, nil
25+
}
26+
27+
// SaveJob save job
28+
func SaveJob(job *Job) error {
29+
return nil
30+
}
31+
32+
// RemoveJobs remove jobs
33+
func RemoveJobs(ids []string) error {
34+
return nil
35+
}
36+
37+
// GetJob get job
38+
func GetJob(id string) (*Job, error) {
39+
return nil, nil
40+
}
41+
42+
// ========================
43+
// Categories methods
44+
// ========================
45+
46+
// GetCategories get categories
47+
func GetCategories(param model.QueryParam) ([]*Category, error) {
48+
return nil, nil
49+
}
50+
51+
// CountCategories count categories
52+
func CountCategories(param model.QueryParam) (int, error) {
53+
return 0, nil
54+
}
55+
56+
// RemoveCategories remove categories
57+
func RemoveCategories(ids []string) error {
58+
return nil
59+
}
60+
61+
// SaveCategory save category
62+
func SaveCategory(category *Category) error {
63+
return nil
64+
}
65+
66+
// ========================
67+
// Logs methods
68+
// ========================
69+
70+
// ListLogs get logs
71+
func ListLogs(id string, param model.QueryParam, page int, pagesize int) (maps.MapStrAny, error) {
72+
return nil, nil
73+
}
74+
75+
// SaveLog save log
76+
func SaveLog(log *Log) error {
77+
return nil
78+
}
79+
80+
// RemoveLogs remove logs
81+
func RemoveLogs(ids []string) error {
82+
return nil
83+
}
84+
85+
// ========================
86+
// Executions methods
87+
// ========================
88+
89+
// GetExecutions get executions
90+
func GetExecutions(id string) ([]*Execution, error) {
91+
return nil, nil
92+
}
93+
94+
// CountExecutions count executions
95+
func CountExecutions(id string, param model.QueryParam) (int, error) {
96+
return 0, nil
97+
}
98+
99+
// RemoveExecutions remove executions
100+
func RemoveExecutions(ids []string) error {
101+
return nil
102+
}
103+
104+
// GetExecution get execution
105+
func GetExecution(id string, param model.QueryParam) (*Execution, error) {
106+
return nil, nil
107+
}
108+
109+
// ========================
110+
// Live progress methods
111+
// ========================
112+
113+
// GetProgress get progress with callback
114+
func GetProgress(id string, cb func(progress *Progress)) (*Progress, error) {
115+
return nil, nil
116+
}

job/execution.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package job
2+
3+
// Add add a new execution to the job
4+
func (j *Job) Add(priority int, handler HandlerFunc) error {
5+
return nil
6+
}
7+
8+
// GetExecutions get executions
9+
func (j *Job) GetExecutions() ([]*Execution, error) {
10+
return nil, nil
11+
}
12+
13+
// GetExecution get execution
14+
func (j *Job) GetExecution(id string) (*Execution, error) {
15+
return nil, nil
16+
}
17+
18+
// Log log
19+
func (e *Execution) Log(level LogLevel, format string, args ...interface{}) error {
20+
return nil
21+
}
22+
23+
// Info info log
24+
func (e *Execution) Info(format string, args ...interface{}) error {
25+
return e.Log(Info, format, args...)
26+
}
27+
28+
// Debug debug log
29+
func (e *Execution) Debug(format string, args ...interface{}) error {
30+
return e.Log(Debug, format, args...)
31+
}
32+
33+
// Warn warn log
34+
func (e *Execution) Warn(format string, args ...interface{}) error {
35+
return e.Log(Warn, format, args...)
36+
}
37+
38+
// Error error log
39+
func (e *Execution) Error(format string, args ...interface{}) error {
40+
return e.Log(Error, format, args...)
41+
}
42+
43+
// Fatal fatal log
44+
func (e *Execution) Fatal(format string, args ...interface{}) error {
45+
return e.Log(Fatal, format, args...)
46+
}
47+
48+
// Panic panic log
49+
func (e *Execution) Panic(format string, args ...interface{}) error {
50+
return e.Log(Panic, format, args...)
51+
}
52+
53+
// Trace trace log
54+
func (e *Execution) Trace(format string, args ...interface{}) error {
55+
return e.Log(Trace, format, args...)
56+
}
57+
58+
// SetProgress set the progress
59+
func (e *Execution) SetProgress(progress int, message string) error {
60+
p := e.Job.Progress()
61+
p.Set(progress, message)
62+
return nil
63+
}

job/interfaces.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package job
2+
3+
// ProgressManager the progress manager
4+
type ProgressManager interface {
5+
Set(progress int, message string) error
6+
}

job/job.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,114 @@
11
package job
2+
3+
import jsoniter "github.com/json-iterator/go"
4+
5+
// Once create a new job
6+
func Once(mode ModeType, data map[string]interface{}) (*Job, error) {
7+
data["mode"] = mode
8+
data["schedule_type"] = ScheduleTypeOnce
9+
raw, err := jsoniter.Marshal(data)
10+
if err != nil {
11+
return nil, err
12+
}
13+
return makeJob(raw)
14+
}
15+
16+
// Cron create a new job
17+
func Cron(mode ModeType, data map[string]interface{}, expression string) (*Job, error) {
18+
data["mode"] = mode
19+
data["schedule_type"] = ScheduleTypeCron
20+
data["schedule_expression"] = expression
21+
raw, err := jsoniter.Marshal(data)
22+
if err != nil {
23+
return nil, err
24+
}
25+
return makeJob(raw)
26+
}
27+
28+
// Daemon create a new job
29+
func Daemon(mode ModeType, data map[string]interface{}) (*Job, error) {
30+
data["mode"] = mode
31+
data["schedule_type"] = ScheduleTypeDaemon
32+
raw, err := jsoniter.Marshal(data)
33+
if err != nil {
34+
return nil, err
35+
}
36+
return makeJob(raw)
37+
}
38+
39+
// Start start the job
40+
func (j *Job) Start() error {
41+
return nil
42+
}
43+
44+
// Cancel cancel the job
45+
func (j *Job) Cancel() error {
46+
return nil
47+
}
48+
49+
// SetData set the data of the job
50+
func (j *Job) SetData(data map[string]interface{}) *Job {
51+
return j
52+
}
53+
54+
// SetConfig set the config of the job
55+
func (j *Job) SetConfig(config map[string]interface{}) *Job {
56+
j.Config = config
57+
return j
58+
}
59+
60+
// SetName set the name of the job
61+
func (j *Job) SetName(name string) *Job {
62+
j.Name = name
63+
return j
64+
}
65+
66+
// SetDescription set the description of the job
67+
func (j *Job) SetDescription(description string) *Job {
68+
j.Description = &description
69+
return j
70+
}
71+
72+
// SetCategory set the category of the job
73+
func (j *Job) SetCategory(category string) *Job {
74+
j.CategoryID = category
75+
return j
76+
}
77+
78+
// SetMaxWorkerNums set the max worker nums of the job
79+
func (j *Job) SetMaxWorkerNums(maxWorkerNums int) *Job {
80+
j.MaxWorkerNums = maxWorkerNums
81+
return j
82+
}
83+
84+
// SetStatus set the status of the job
85+
func (j *Job) SetStatus(status string) *Job {
86+
j.Status = status
87+
return j
88+
}
89+
90+
// SetMaxRetryCount set the max retry count of the job
91+
func (j *Job) SetMaxRetryCount(maxRetryCount int) *Job {
92+
j.MaxRetryCount = maxRetryCount
93+
return j
94+
}
95+
96+
// SetDefaultTimeout set the default timeout of the job
97+
func (j *Job) SetDefaultTimeout(defaultTimeout int) *Job {
98+
j.DefaultTimeout = &defaultTimeout
99+
return j
100+
}
101+
102+
// SetMode set the mode of the job
103+
func (j *Job) SetMode(mode ModeType) {
104+
j.Mode = mode
105+
}
106+
107+
func makeJob(data []byte) (*Job, error) {
108+
var job Job
109+
err := jsoniter.Unmarshal(data, &job)
110+
if err != nil {
111+
return nil, err
112+
}
113+
return &job, nil
114+
}

0 commit comments

Comments
 (0)