Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(worker): delay duration #7496

Conversation

djabarovgeorge
Copy link
Contributor

What changed? Why was the change needed?

Screenshots

Expand for optional sections

Related enterprise PR

Special notes for your reviewer

Copy link

netlify bot commented Jan 13, 2025

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit 4494044
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/67911112b9b62400085a12f0
😎 Deploy Preview https://deploy-preview-7496.dashboard.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 site configuration.

Copy link

netlify bot commented Jan 13, 2025

Deploy Preview for dashboard-v2-novu-staging ready!

Name Link
🔨 Latest commit 4494044
🔍 Latest deploy log https://app.netlify.com/sites/dashboard-v2-novu-staging/deploys/67911112e3fe2f00087b13ae
😎 Deploy Preview https://deploy-preview-7496.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 site configuration.

…duration-limits-for-digest-and-delay-steps-in-code-first
@djabarovgeorge djabarovgeorge marked this pull request as ready for review January 14, 2025 23:55
* If queueNextJob.execute returns undefined, we stop the workflow.
* Otherwise, we continue trying to queue the next job in the chain.
*/
private async tryQueueNextJobs(job: JobEntity): Promise<void> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was needed because not we have a possible exception on finally block which is not handled.

for the following workflow SMS => DELAY => IN-APP
the problem is the we handle the delay step (calculate the duration) while we executing the SMS job.
a better solution would be to handle the DELAY step while we execute the DELAY job.
a refactor will take a lot of time and we will need to create backward compatibility support for old jobs as well.

const cronExpression = parseCronExpression(command.cron);
const firstTime = cronExpression.next().toDate();
const secondTime = cronExpression.next().toDate();
private isCronDeltaDeferDurationExceededTier(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i tried to create a simple "smart solution" however on every approach it became very complicated very fast, therefore I created a more simple solution where we validate the next 50 iterations of the crown with an exit if we pass 2 years.

@@ -142,6 +166,10 @@ const isCronExpression = (cron: string) => {
};

const isRegularDeferAction = (command: TierRestrictionsValidateCommand) => {
if (command.deferDurationMs) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

a bug we had, where we did not check the deferDurationMs that the worker was passing.

djabarovgeorge and others added 2 commits January 15, 2025 02:19
…duration-limits-for-digest-and-delay-steps-in-code-first
djabarovgeorge and others added 2 commits January 15, 2025 02:22
…mits-for-digest-and-delay-steps-in-code-first' into nv-5144-enforce-tier-duration-limits-for-digest-and-delay-steps-in-code-first
if (errors.length > 0) {
const errorMessages = errors?.map((error) => error.message).join(', ');
Logger.warn({ errors, jobId: job._id }, errorMessages, LOG_CONTEXT);
const uniqueErrors = _.uniq(errors.map((error) => error.message));
Copy link
Contributor

Choose a reason for hiding this comment

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

In what cases was this not unique?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, at the moment if the user has a tier duration error we will duplicate the error to the unit and amount properties so that we will persist it, and the UI will decide how to represent it.
However, we do not need this duplication in the execution detail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, thanks for the explanation 🙏

…duration-limits-for-digest-and-delay-steps-in-code-first
…mits-for-digest-and-delay-steps-in-code-first' into nv-5144-enforce-tier-duration-limits-for-digest-and-delay-steps-in-code-first
@djabarovgeorge djabarovgeorge merged commit b043aef into next Jan 22, 2025
30 of 31 checks passed
@djabarovgeorge djabarovgeorge deleted the nv-5144-enforce-tier-duration-limits-for-digest-and-delay-steps-in-code-first branch January 22, 2025 16:08
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