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

Feature mail scheduler #13

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Loulou5702
Copy link
Contributor

This new feature allows the scheduler to plan and send newsletters as needed, according to a defined periodicity.

For now, the script executed when sending emails is a simple "hello world" in the console to avoid consuming emails in Postmark. However, you can replace it with the actual newsletter-sending script that we have already developed.

The script checks every 10 seconds if there are newsletters to send. If so, it executes the specified script (currently "hello.ts" for testing purposes).

After sending an email, it schedules the next one based on the user's chosen periodicity.

In this example, we plan to send two newsletters at 19:10.
One person wants another newsletter in 5 minutes, and the other in 6 minutes (this demonstrates different periodicity management).

Example in the terminal :
image

Looking at the database after execution :
image

}

console.log("🟢 Newsletter Scheduler started... Press CTRL + C to stop.");
setInterval(checkAndSendNewsletters, INTERVAL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought: Smart approach but we usually use cron jobs to run this kind of script: cron is designed for this and is more efficient. You can search on the internet for setInterval vs cron to make your own opinion.
To do thah you can set up node-cron for instance https://www.digitalocean.com/community/tutorials/nodejs-cron-jobs-by-examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants