Skip to content

Commit

Permalink
Update monitor payload
Browse files Browse the repository at this point in the history
  • Loading branch information
AchoArnold committed Dec 5, 2023
1 parent 582bf6a commit 46a219f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions api/pkg/services/heartbeat_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,21 @@ func (service *HeartbeatService) Monitor(ctx context.Context, params *HeartbeatM

ctxLogger := service.tracer.CtxLogger(service.logger, span)

exists, err := service.monitorRepository.Exists(ctx, params.UserID, params.MonitorID)
monitor, err := service.monitorRepository.Load(ctx, params.UserID, params.Owner)
if err != nil && stacktrace.GetCode(err) != repositories.ErrCodeNotFound {
ctxLogger.Info(fmt.Sprintf("heartbeat monitor does not exist for owner [%s] and user [%s]", params.Owner, params.UserID))
return nil
}

if err != nil {
msg := fmt.Sprintf("cannot check if monitor exists with userID [%s] and owner [%s]", params.UserID, params.Owner)
ctxLogger.Error(stacktrace.Propagate(err, msg))
return service.scheduleHeartbeatCheck(ctx, time.Now().UTC(), params)
}

if !exists {
ctxLogger.Info(fmt.Sprintf("heartbeat monitor does not exist for owner [%s] and user [%s]", params.Owner, params.UserID))
return nil
}
// Update params in case of ID duplicate
params.PhoneID = monitor.PhoneID
params.MonitorID = monitor.ID

heartbeat, err := service.repository.Last(ctx, params.UserID, params.Owner)
if err != nil {
Expand Down

0 comments on commit 46a219f

Please sign in to comment.