Skip to content

Commit 3997cd5

Browse files
committed
style: 优化的日志信息
1 parent 3a5051b commit 3997cd5

File tree

7 files changed

+26
-20
lines changed

7 files changed

+26
-20
lines changed

module/worker/recv_exec.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ func (pod *RecvPod) Exec(rs *SocketData) error {
1717
data *command.ExecPayload
1818
)
1919

20+
log.Println("Exec:recv", rs.Payload)
21+
2022
if mapstructure.Decode(rs.Payload, &data) == nil {
21-
log.Println("Exec:wait", data.Name)
2223
ret, err = command.Exec(data)
2324
} else {
2425
err = errors.New("无法解析请求参数")
2526
}
2627

2728
if err != nil {
28-
log.Println("Exec:error", err)
29+
log.Println("Exec:fail", err)
2930
} else {
3031
log.Println("Exec:done", data.Name)
3132
}
@@ -40,11 +41,5 @@ func (pod *RecvPod) Exec(rs *SocketData) error {
4041
},
4142
}
4243

43-
if err := pod.Write(rq); err != nil {
44-
log.Println("Exec:resp", err)
45-
return err
46-
}
47-
48-
return err
49-
44+
return pod.Write(rq)
5045
}

module/worker/recv_stat.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ import (
88

99
func (pod *RecvPod) Stat(rs *SocketData) error {
1010

11+
log.Println("Stat:recv Id", rs.TaskId)
12+
1113
rq := &SocketData{
1214
Method: "Stat:resp",
1315
TaskId: rs.TaskId,
1416
Payload: psutil.Detail(),
1517
}
1618

17-
if err := pod.Write(rq); err != nil {
18-
log.Println("Exec:resp", err)
19-
return err
20-
}
21-
22-
return nil
19+
return pod.Write(rq)
2320

2421
}

module/worker/send_ping.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99

1010
func (pod *SendPod) Ping() (uint, error) {
1111

12+
log.Println("Ping:send", "SummaryStat")
13+
1214
rq := &SocketData{
1315
Method: "Ping",
1416
TaskId: 0,
1517
Payload: psutil.Summary(),
1618
}
1719

18-
log.Println("Ping:send", "SummaryStat")
19-
2020
return rq.TaskId, pod.Write(rq)
2121

2222
}
@@ -33,7 +33,7 @@ func PingLoop(pod *SendPod) error {
3333

3434
for {
3535
if _, err := pod.Ping(); err != nil {
36-
log.Println("Ping:error", err)
36+
log.Println("Ping:fail", err)
3737
return err
3838
}
3939
time.Sleep(25 * time.Second)

module/workhub/poolman.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func WorkerOfUser(userId uint) []*Worker {
6363

6464
}
6565

66-
func NewSender(workerId string) *SendPod {
66+
func NewSender(id string) *SendPod {
6767

68-
if worker, ok := workerPool[workerId]; ok {
68+
if worker, ok := workerPool[id]; ok {
6969
return &SendPod{worker}
7070
}
7171

module/workhub/recv_ping.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package workhub
22

33
import (
4+
"log"
5+
46
"github.com/mitchellh/mapstructure"
57
)
68

79
func (pod *RecvPod) Ping(rq *SocketData) error {
810

11+
log.Println("Ping:recv By", pod.WorkerMeta.HostName)
12+
913
mapstructure.Decode(rq.Payload, &pod.WorkerMeta)
1014

1115
rs := &SocketData{

module/workhub/send_exec.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package workhub
22

33
import (
4+
"log"
45
"tdp-cloud/helper/command"
56
)
67

78
func (pod *SendPod) Exec(data *command.ExecPayload) (uint, error) {
89

10+
log.Println("Exec:send To", pod.WorkerMeta.HostName)
11+
912
taskId := createHistory(pod, data)
1013

1114
rq := &SocketData{
@@ -20,6 +23,8 @@ func (pod *SendPod) Exec(data *command.ExecPayload) (uint, error) {
2023

2124
func (pod *RespPod) Exec(rq *SocketData) {
2225

26+
log.Println("Exec:resp By", pod.WorkerMeta.HostName)
27+
2328
updateHistory(pod, rq)
2429

2530
}

module/workhub/send_stat.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package workhub
22

33
import (
4+
"log"
45
"time"
56
)
67

78
func (pod *SendPod) Stat() (uint, error) {
89

10+
log.Println("Stat:send To", pod.WorkerMeta.HostName)
11+
912
rq := &SocketData{
1013
Method: "Stat",
1114
TaskId: uint(time.Now().Unix()),
@@ -17,6 +20,8 @@ func (pod *SendPod) Stat() (uint, error) {
1720

1821
func (pod *RespPod) Stat(rq *SocketData) {
1922

23+
log.Println("Stat:resp By", pod.WorkerMeta.HostName)
24+
2025
workerResp[rq.TaskId] = rq.Payload
2126

2227
}

0 commit comments

Comments
 (0)