MCPcopy
hub / github.com/IceWhaleTech/CasaOS / SendFileOperateNotify

Method SendFileOperateNotify

service/notify.go:73–229  ·  view source on GitHub ↗

Send periodic broadcast messages

(nowSend bool)

Source from the content-addressed store, hash-verified

71
72// Send periodic broadcast messages
73func (i *notifyServer) SendFileOperateNotify(nowSend bool) {
74 if nowSend {
75 len := 0
76 FileQueue.Range(func(k, v interface{}) bool {
77 len++
78 return true
79 })
80
81 model := notify.NotifyModel{}
82 listMsg := make(map[string]interface{})
83 if len == 0 {
84 model.Data = []string{}
85 listMsg["file_operate"] = model
86 msg := make(map[string]string)
87 for k, v := range listMsg {
88 bt, _ := json.Marshal(v)
89 msg[k] = string(bt)
90 }
91 response, err := MyService.MessageBus().PublishEventWithResponse(context.Background(), common.SERVICENAME, "casaos:file:operate", msg)
92 if err != nil {
93 logger.Error("failed to publish event to message bus", zap.Error(err), zap.Any("event", msg))
94 }
95 if response.StatusCode() != http.StatusOK {
96 logger.Error("failed to publish event to message bus", zap.String("status", response.Status()), zap.Any("response", response))
97 }
98 return
99 }
100
101 model.State = "NORMAL"
102 list := []notify.File{}
103 OpStrArrbak := OpStrArr
104
105 for _, v := range OpStrArrbak {
106 tempItem, ok := FileQueue.Load(v)
107 temp := tempItem.(model2.FileOperate)
108 if !ok {
109 continue
110 }
111 task := notify.File{}
112 task.Id = v
113 task.ProcessedSize = temp.ProcessedSize
114 task.TotalSize = temp.TotalSize
115 task.To = temp.To
116 task.Type = temp.Type
117 if task.ProcessedSize == 0 {
118 task.Status = "STARTING"
119 } else {
120 task.Status = "PROCESSING"
121 }
122
123 if temp.Finished || temp.ProcessedSize >= temp.TotalSize {
124
125 task.Finished = true
126 task.Status = "FINISHED"
127 FileQueue.Delete(v)
128 OpStrArr = OpStrArr[1:]
129 go ExecOpFile()
130 list = append(list, task)

Callers

nothing calls this directly

Calls 6

ExecOpFileFunction · 0.85
RangeMethod · 0.80
LoadMethod · 0.80
MessageBusMethod · 0.65
DeleteMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected