Skip to content

Commit 7ec17b3

Browse files
committed
Don't schedule monitor when it doesn't exist
1 parent 3fc8a7d commit 7ec17b3

6 files changed

Lines changed: 10 additions & 9 deletions

File tree

api/pkg/handlers/events_handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ func (h *EventsHandler) Dispatch(c *fiber.Ctx) error {
6868
return h.responseForbidden(c)
6969
}
7070

71+
ctxLogger.Info(fmt.Sprintf("handling [%s] event with ID [%s]", request.Type(), request.ID()))
7172
err := h.service.DispatchSync(ctx, request)
7273
if err != nil {
73-
msg := fmt.Sprintf("cannot dispatch event with ID [%s]", request.ID())
74+
msg := fmt.Sprintf("cannot dispatch [%s] event with ID [%s]", request.Type(), request.ID())
7475
ctxLogger.Error(stacktrace.Propagate(err, msg))
7576
return h.responseInternalServerError(c)
7677
}

api/pkg/repositories/gorm_heartbeat_monitor_repository.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (repository *gormHeartbeatMonitorRepository) Load(ctx context.Context, user
123123
}
124124

125125
// Exists checks of a heartbeat monitor exists for the userID and owner
126-
func (repository *gormHeartbeatMonitorRepository) Exists(ctx context.Context, userID entities.UserID, owner string) (bool, error) {
126+
func (repository *gormHeartbeatMonitorRepository) Exists(ctx context.Context, userID entities.UserID, monitorID uuid.UUID) (bool, error) {
127127
ctx, span := repository.tracer.Start(ctx)
128128
defer span.End()
129129

@@ -132,10 +132,10 @@ func (repository *gormHeartbeatMonitorRepository) Exists(ctx context.Context, us
132132
Model(&entities.HeartbeatMonitor{}).
133133
Select("count(*) > 0").
134134
Where("user_id = ?", userID).
135-
Where("owner = ?", owner).
135+
Where("id = ?", monitorID).
136136
Find(&exists).Error
137137
if err != nil {
138-
msg := fmt.Sprintf("cannot check if heartbeat monitor exists with userID [%s] and owner [%s]", userID, owner)
138+
msg := fmt.Sprintf("cannot check if heartbeat monitor exists with userID [%s] and montiorID [%s]", userID, monitorID)
139139
return exists, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
140140
}
141141

api/pkg/repositories/heartbeat_monitor_repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type HeartbeatMonitorRepository interface {
1717
Load(ctx context.Context, userID entities.UserID, phoneNumber string) (*entities.HeartbeatMonitor, error)
1818

1919
// Exists checks if a heartbeat monitor exists for a phone number
20-
Exists(ctx context.Context, userID entities.UserID, phoneNumber string) (bool, error)
20+
Exists(ctx context.Context, userID entities.UserID, monitorID uuid.UUID) (bool, error)
2121

2222
// UpdateQueueID updates the queueID of a monitor
2323
UpdateQueueID(ctx context.Context, monitorID uuid.UUID, queueID string) error

api/pkg/services/event_dispatcher_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (dispatcher *EventDispatcher) Publish(ctx context.Context, event cloudevent
103103

104104
subscribers, ok := dispatcher.listeners[event.Type()]
105105
if !ok {
106-
ctxLogger.Info(fmt.Sprintf("no listener is configured for event type [%s]", event.Type()))
106+
ctxLogger.Info(fmt.Sprintf("no listener is configured for event type [%s] with id [%s]", event.Type(), event.ID()))
107107
return
108108
}
109109

api/pkg/services/google_cloud_push_queue_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (queue *googlePushQueue) Enqueue(ctx context.Context, task *PushQueueTask,
7777
"item added to [%s] queue with id [%s] and schedule [%s]",
7878
queue.queueConfig.Name,
7979
queueTask.Name,
80-
queueTask.ScheduleTime,
80+
queueTask.GetScheduleTime().AsTime(),
8181
))
8282

8383
return queueTask.Name, nil

api/pkg/services/heartbeat_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func (service *HeartbeatService) Monitor(ctx context.Context, params *HeartbeatM
203203

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

206-
exists, err := service.monitorRepository.Exists(ctx, params.UserID, params.Owner)
206+
exists, err := service.monitorRepository.Exists(ctx, params.UserID, params.MonitorID)
207207
if err != nil {
208208
msg := fmt.Sprintf("cannot check if monitor exists with userID [%s] and owner [%s]", params.UserID, params.Owner)
209209
ctxLogger.Error(stacktrace.Propagate(err, msg))
@@ -217,7 +217,7 @@ func (service *HeartbeatService) Monitor(ctx context.Context, params *HeartbeatM
217217

218218
heartbeat, err := service.repository.Last(ctx, params.UserID, params.Owner)
219219
if err != nil {
220-
msg := fmt.Sprintf("cannot fetch last heartbeat for userID [%s] and owner [%s] removing check", params.UserID, params.Owner)
220+
msg := fmt.Sprintf("cannot fetch last heartbeat for userID [%s] and owner [%s] and ID [%s] removing check", params.UserID, params.Owner, params.MonitorID)
221221
ctxLogger.Error(stacktrace.Propagate(err, msg))
222222
return nil
223223
}

0 commit comments

Comments
 (0)