MCPcopy Index your code
hub / github.com/NdoleStudio/httpsms / StoreMonitor

Method StoreMonitor

api/pkg/services/heartbeat_service.go:182–212  ·  view source on GitHub ↗

StoreMonitor a new entities.HeartbeatMonitor

(ctx context.Context, params *HeartbeatMonitorStoreParams)

Source from the content-addressed store, hash-verified

180
181// StoreMonitor a new entities.HeartbeatMonitor
182func (service *HeartbeatService) StoreMonitor(ctx context.Context, params *HeartbeatMonitorStoreParams) (*entities.HeartbeatMonitor, error) {
183 ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger)
184 defer span.End()
185
186 monitor, scheduleCheck, err := service.phoneMonitor(ctx, params)
187 if err != nil {
188 msg := fmt.Sprintf("cannot create monitor for with userID [%s] and owner [%s]", params.UserID, params.Owner)
189 return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
190 }
191
192 if !scheduleCheck {
193 ctxLogger.Info(fmt.Sprintf("heartbeat monitor [%s] for owner [%s] does not need scheduling because it was updated at [%s]", monitor.ID, monitor.Owner, monitor.UpdatedAt))
194 return monitor, nil
195 }
196
197 ctxLogger.Info(fmt.Sprintf("scheduling heartbeat monitor [%s] for owner [%s] and user [%s]", monitor.ID, monitor.Owner, monitor.UserID))
198
199 monitorParams := &HeartbeatMonitorParams{
200 Owner: monitor.Owner,
201 PhoneID: monitor.PhoneID,
202 UserID: monitor.UserID,
203 MonitorID: monitor.ID,
204 Source: params.Source,
205 }
206 if err = service.scheduleHeartbeatCheck(ctx, time.Now().UTC(), monitorParams); err != nil {
207 msg := fmt.Sprintf("cannot schedule healthcheck for monitor [%s] with owner [%s] and userID [%s]", monitor.ID, params.Owner, params.UserID)
208 return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
209 }
210
211 return monitor, nil
212}
213
214func (service *HeartbeatService) phoneMonitor(ctx context.Context, params *HeartbeatMonitorStoreParams) (*entities.HeartbeatMonitor, bool, error) {
215 ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger)

Callers 1

onPhoneUpdatedMethod · 0.80

Calls 5

phoneMonitorMethod · 0.95
StartWithLoggerMethod · 0.65
WrapErrorSpanMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected