Send periodic broadcast messages
(nowSend bool)
| 71 | |
| 72 | // Send periodic broadcast messages |
| 73 | func (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) |
nothing calls this directly
no test coverage detected