-
Notifications
You must be signed in to change notification settings - Fork 263
/
job_execute_repo.go
108 lines (95 loc) · 2.73 KB
/
job_execute_repo.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
package repos
import (
"database/sql"
"github.com/ixre/go2o/core/domain/interface/job"
jobImpl "github.com/ixre/go2o/core/domain/job"
"github.com/ixre/gof/db/orm"
"github.com/ixre/gof/storage"
"log"
)
var _ job.IJobRepo = new(jobRepositoryImpl)
type jobRepositoryImpl struct {
_orm orm.Orm
}
func (j *jobRepositoryImpl) CreateJob(data *job.ExecData) job.IJobAggregate {
return jobImpl.NewJobImpl(j, data)
}
var jobRepoImplMapped = false
// NewJobRepository Create new JobExecDataDao
func NewJobRepository(o orm.Orm, sto storage.Interface) job.IJobRepo {
if !jobRepoImplMapped {
_ = o.Mapping(job.ExecData{}, "job_exec_data")
_ = o.Mapping(job.ExecFail{}, "job_exec_fail")
_ = o.Mapping(job.ExecRequeue{}, "exec_re_queue")
jobRepoImplMapped = true
}
return &jobRepositoryImpl{
_orm: o,
}
}
// GetExecData Get JobExecData
func (j *jobRepositoryImpl) GetExecData(primary interface{}) *job.ExecData {
e := job.ExecData{}
err := j._orm.Get(primary, &e)
if err == nil {
return &e
}
if err != sql.ErrNoRows {
log.Println("[ Orm][ Error]:", err.Error(), "; Entity:ExecData")
}
return nil
}
// GetExecDataBy GetBy JobExecData
func (j *jobRepositoryImpl) GetExecDataBy(where string, v ...interface{}) *job.ExecData {
e := job.ExecData{}
err := j._orm.GetBy(&e, where, v...)
if err == nil {
return &e
}
if err != sql.ErrNoRows {
log.Println("[ Orm][ Error]:", err.Error(), "; Entity:ExecData")
}
return nil
}
func (j *jobRepositoryImpl) GetJobByName(name string) job.IJobAggregate {
v := j.GetExecDataBy("job_name = $1 ORDER BY id ASC limit 1", name)
if v != nil {
return j.CreateJob(v)
}
return nil
}
// SaveExecData Save JobExecData
func (j *jobRepositoryImpl) SaveExecData(v *job.ExecData) (int, error) {
id, err := orm.Save(j._orm, v, int(v.Id))
if err != nil && err != sql.ErrNoRows {
log.Println("[ Orm][ Error]:", err.Error(), "; Entity:ExecData")
}
return id, err
}
// GetExecFailBy GetBy 任务执行失败
func (j *jobRepositoryImpl) GetExecFailBy(where string, v ...interface{}) *job.ExecFail {
e := job.ExecFail{}
err := j._orm.GetBy(&e, where, v...)
if err == nil {
return &e
}
if err != sql.ErrNoRows {
log.Println("[ Orm][ Error]:", err.Error(), "; Entity:ExecFail")
}
return nil
}
// SaveExecFail Save 任务执行失败
func (j *jobRepositoryImpl) SaveExecFail(v *job.ExecFail) (int, error) {
id, err := orm.Save(j._orm, v, int(v.Id))
if err != nil && err != sql.ErrNoRows {
log.Println("[ Orm][ Error]:", err.Error(), "; Entity:ExecFail")
}
return id, err
}
func (j *jobRepositoryImpl) SaveRequeue(v *job.ExecRequeue) (int, error) {
id, err := orm.Save(j._orm, v, int(v.Id))
if err != nil && err != sql.ErrNoRows {
log.Println("[ Orm][ Error]:", err.Error(), "; Entity:ReQueue")
}
return id, err
}