Skip to content

Conversation

LetItRock
Copy link
Contributor

What changed? Why was the change needed?

Worker: skip sending messages when outside of the subscriber's schedule.

Screenshots

Screen.Recording.2025-09-11.at.16.06.30.mp4
Screen.Recording.2025-09-11.at.16.17.27.mov

@LetItRock LetItRock requested a review from scopsy September 11, 2025 22:18
@LetItRock LetItRock self-assigned this Sep 11, 2025
@linear
Copy link

linear bot commented Sep 11, 2025

@github-actions github-actions bot changed the title feat(api,worker): skip sending messages outside of the subscribers schedule feat(api,worker): skip sending messages outside of the subscribers schedule fixes NV-6618 Sep 11, 2025
@@ -1,4 +1,5 @@
import {
GetSubscriberSchedule,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to the application-generic

IS_STEP_RUN_LOGS_WRITE_ENABLED=true
IS_WORKFLOW_RUN_LOGS_WRITE_ENABLED=true
IS_NOTIFICATION_SEVERITY_ENABLED=true
IS_SUBSCRIBERS_SCHEDULE_ENABLED=true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the worker logic to work when running e2e tests

environment: { _id: job._environmentId },
});

if (isSubscribersScheduleEnabled && !this.shouldSkipScheduleCheck(job, notification)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the trigger, in-app, digest, delay and critical workflows will be "skipped" when checking the schedule

{ readPreference: 'secondaryPreferred' }
);

if (!isWithinSchedule(schedule, new Date(), subscriber?.timezone)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not within the schedule (outside), then cancel the job and provide the step_run and trace details

import { expect } from 'chai';
import { isWithinSchedule } from './schedule-validator';

describe('ScheduleValidator', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit tests to cover isWithinSchedule logic

const daysToCheck = [currentDay];

// For overnight schedules, also check the previous day
const previousDay = getPreviousDay(currentDay);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the overnight schedules are for example happening in this case when:

  • hours are set monday 11:00 PM - 2:00 AM
  • current time is tuesday 1:00 AM
    so we have to take a look at the schedule of the previous day

Base automatically changed from nv-6617-dashboard-subscribers-schedule to next September 11, 2025 22:32
@netlify
Copy link

netlify bot commented Sep 11, 2025

Deploy preview added

Name Link
🔨 Latest commit 7bbd110
🔍 Latest deploy log https://app.netlify.com/projects/dashboard-v2-novu-staging/deploys/68c34e37f9eabc0008093496
😎 Deploy Preview https://deploy-preview-9126.dashboard-v2.novu-staging.co
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines +136 to +152
const schedule = await this.getSubscriberSchedule.execute(
GetSubscriberScheduleCommand.create({
environmentId: job._environmentId,
organizationId: job._organizationId,
_subscriberId: job._subscriberId,
})
);

const subscriber = await this.subscriberRepository.findOne(
{
_id: job._subscriberId,
_environmentId: job._environmentId,
_organizationId: job._organizationId,
},
'timezone',
{ readPreference: 'secondaryPreferred' }
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a general note, if the subscriber is refetched again in the schedule usecase, or soemwhere up the scope, better to reuse it to avoid a duplicate db call if possible. (not sure if it's the case here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those two were made to be lightweight:

  • the getSubscriberSchedule only uses one request to read preferences, nothing more
  • the this.subscriberRepository.findOne is done to secondary replica and only fetch timezone

@LetItRock LetItRock merged commit a2581a8 into next Sep 15, 2025
32 checks passed
@LetItRock LetItRock deleted the nv-6618-skip-messages-outside-of-the-subscribers-schedule branch September 15, 2025 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants