-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_job.go
70 lines (62 loc) · 1.88 KB
/
type_job.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
package telescope
import (
"fmt"
app2 "github.com/go-home-admin/home/app"
"github.com/go-home-admin/home/bootstrap/constraint"
"github.com/go-home-admin/home/bootstrap/servers"
"github.com/go-home-admin/home/bootstrap/services/app"
uuid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
"time"
)
// Job @Bean
type Job struct {
Status string `json:"status"`
Connection string `json:"connection"`
Queue string `json:"queue"`
Name string `json:"name"`
Tries interface{} `json:"tries"`
Timeout interface{} `json:"timeout"`
Data interface{} `json:"data"`
Hostname string `json:"hostname"`
}
func (j *Job) Boot() {
if app2.IsDebug() && app.HasBean("queue") {
server := app.GetBean("queue").(*servers.Queue)
server.AddMiddleware(func(job constraint.Job, next func(constraint.Job)) {
TelescopeStart()
defer TelescopeClose()
defer func() {
// 记录调试信息
logrus.WithFields(logrus.Fields{
"type": "job",
"status": "processed",
"connection": app2.Config("queue.connection", "redis"),
"queue": app2.Config("queue.queue.stream_name", "home_default_stream"),
"data": job,
}).Debug(fmt.Sprintf("%T", job))
}()
next(job)
})
}
}
func (j *Job) BindType() string {
return "job"
}
func (j *Job) Handler(entry *logrus.Entry) (*entries, []tag) {
b := *j
b.Name = entry.Message
b.Data = entry.Data["data"]
b.Status = entry.Data["status"].(string)
b.Queue = entry.Data["queue"].(string)
b.Connection = entry.Data["connection"].(string)
return &entries{
Uuid: uuid.NewV4().String(),
BatchId: NewtelescopeHook().TelescopeUUID(),
FamilyHash: nil,
ShouldDisplayOnIndex: 1,
Type: b.BindType(),
Content: ToContent(b),
CreatedAt: time.Now().Format("2006-01-02 15:04:05"),
}, nil
}