setError sets the folder state to FolderError with the specified error or to FolderIdle if the error is nil
(err error)
| 149 | // setError sets the folder state to FolderError with the specified error or |
| 150 | // to FolderIdle if the error is nil |
| 151 | func (s *stateTracker) setError(err error) { |
| 152 | s.mut.Lock() |
| 153 | defer s.mut.Unlock() |
| 154 | |
| 155 | defer func() { |
| 156 | metricFolderState.WithLabelValues(s.folderID).Set(float64(s.current)) |
| 157 | }() |
| 158 | |
| 159 | eventData := map[string]interface{}{ |
| 160 | "folder": s.folderID, |
| 161 | "from": s.current.String(), |
| 162 | } |
| 163 | |
| 164 | if err != nil && s.current != FolderError { |
| 165 | slog.Warn("Folder is in error state", slog.String("folder", s.folderID), slogutil.Error(err)) |
| 166 | } else if err == nil && s.current == FolderError { |
| 167 | slog.Info("Folder error state was cleared", slog.String("folder", s.folderID)) |
| 168 | } |
| 169 | |
| 170 | if err != nil { |
| 171 | eventData["error"] = err.Error() |
| 172 | s.current = FolderError |
| 173 | } else { |
| 174 | s.current = FolderIdle |
| 175 | } |
| 176 | |
| 177 | eventData["to"] = s.current.String() |
| 178 | |
| 179 | if !s.changed.IsZero() { |
| 180 | eventData["duration"] = time.Since(s.changed).Seconds() |
| 181 | } |
| 182 | |
| 183 | s.err = err |
| 184 | s.changed = time.Now().Truncate(time.Second) |
| 185 | |
| 186 | s.evLogger.Log(events.StateChanged, eventData) |
| 187 | } |