Skip to content

Commit cc64f1c

Browse files
committed
Add logic for publishing event when phone is offline or online
1 parent 06b3a71 commit cc64f1c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

api/pkg/services/heartbeat_service.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ func (service *HeartbeatService) handleHeartbeatWhenPhoneWasOffline(ctx context.
126126
ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger)
127127
defer span.End()
128128

129+
if err := service.UpdatePhoneOnline(ctx, monitor.UserID, monitor.ID, true); err != nil {
130+
msg := fmt.Sprintf("cannot update phone online status for heartbeat monitor [%s]", monitor.ID)
131+
ctxLogger.Error(service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)))
132+
}
133+
129134
event, err := service.createEvent(events.EventTypePhoneHeartbeatOnline, source, &events.PhoneHeartbeatOnlinePayload{
130135
PhoneID: monitor.PhoneID,
131136
UserID: monitor.UserID,
@@ -240,11 +245,11 @@ func (service *HeartbeatService) UpdatePhoneOnline(ctx context.Context, userID e
240245
ctxLogger := service.tracer.CtxLogger(service.logger, span)
241246

242247
if err := service.monitorRepository.UpdatePhoneOnline(ctx, userID, monitorID, phoneOnline); err != nil {
243-
msg := fmt.Sprintf("cannot update heartbeat monitor [%s] with userID [%s] and status [%s]", monitorID, userID, phoneOnline)
248+
msg := fmt.Sprintf("cannot update heartbeat monitor [%s] with userID [%s] and status [%t]", monitorID, userID, phoneOnline)
244249
return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
245250
}
246251

247-
ctxLogger.Info(fmt.Sprintf("heartbeat monitor [%s] updated for userID [%s] and status [%s]", monitorID, userID, phoneOnline))
252+
ctxLogger.Info(fmt.Sprintf("heartbeat monitor [%s] updated for userID [%s] and status [%t]", monitorID, userID, phoneOnline))
248253
return nil
249254
}
250255

0 commit comments

Comments
 (0)