Skip to content

Commit 9af04e3

Browse files
AchoArnoldCopilot
andcommitted
feat(services): add ExactSendTime bypass in PhoneNotificationService.Schedule
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2a8b83a commit 9af04e3

1 file changed

Lines changed: 39 additions & 8 deletions

File tree

api/pkg/services/phone_notification_service.go

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,16 @@ func (service *PhoneNotificationService) Send(ctx context.Context, params *Phone
161161

162162
// PhoneNotificationScheduleParams are parameters for sending a notification
163163
type PhoneNotificationScheduleParams struct {
164-
UserID entities.UserID
165-
Owner string
166-
Source string
167-
Encrypted bool
168-
Contact string
169-
Content string
170-
SIM entities.SIM
171-
MessageID uuid.UUID
164+
UserID entities.UserID
165+
Owner string
166+
Source string
167+
Encrypted bool
168+
Contact string
169+
Content string
170+
SIM entities.SIM
171+
MessageID uuid.UUID
172+
ExactSendTime bool
173+
ScheduledSendTime *time.Time
172174
}
173175

174176
// Schedule a notification to be sent to a phone
@@ -195,6 +197,35 @@ func (service *PhoneNotificationService) Schedule(ctx context.Context, params *P
195197
UpdatedAt: time.Now().UTC(),
196198
}
197199

200+
// Bypass rate-limit and schedule window logic for exact send time
201+
if params.ExactSendTime && params.ScheduledSendTime != nil {
202+
scheduledAt := *params.ScheduledSendTime
203+
if scheduledAt.Before(time.Now().UTC()) {
204+
scheduledAt = time.Now().UTC()
205+
}
206+
notification.ScheduledAt = scheduledAt
207+
if err = service.phoneNotificationRepository.ScheduleExact(ctx, notification); err != nil {
208+
msg := fmt.Sprintf("cannot schedule exact notification for message [%s] to phone [%s]", params.MessageID, phone.ID)
209+
return service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
210+
}
211+
212+
if err = service.dispatchMessageNotificationScheduled(ctx, params, notification); err != nil {
213+
ctxLogger.Error(err)
214+
}
215+
216+
if err = service.dispatchMessageNotificationSend(ctx, params.Source, notification); err != nil {
217+
return service.tracer.WrapErrorSpan(span, err)
218+
}
219+
220+
ctxLogger.Info(fmt.Sprintf(
221+
"message with id [%s] exact notification scheduled for [%s] with id [%s]",
222+
params.MessageID,
223+
notification.ScheduledAt,
224+
notification.ID,
225+
))
226+
return nil
227+
}
228+
198229
var schedule *entities.MessageSendSchedule
199230
if phone.ScheduleID != nil {
200231
schedule, err = service.sendScheduleRepository.Load(ctx, params.UserID, *phone.ScheduleID)

0 commit comments

Comments
 (0)