I am using the NodeJS Agenda Scheduler and I wish to know a few things before going to production.
There are 3 scenarios
A User called Peter wants to schedule a Message to be sent by 5PM on the Second of July 2022
Another User called Mary wants to schedule a Message to be sent by 10PM on the 15th of August 2022.
For every new request to schedule a new message to be sent in the future I am creating a new Job for it using the function below
defineNewJob(messageId, jobDate) {
let jobName = `send_${messageId}`;
try {
agenda.define(jobName, jobHandler);
await agenda.schedule(jobDate, jobName, { message_id: messageId, removeOnCompleted: true });
} catch (e) {
console.log(`Error Scheduling Job`);
}
}
This means that I might end up with over 1 million messages from different users all to be scheduled in the future at completely different times and stored in the MongoDB database
- I noticed that when I restart my server, Agenda has lost all I scheduled so I need to read back the data from my database and call the function above again with each of the returned messages from my database. Is this an efficient way to do things? I don't think so.
Please currently the scheduling works flawlessly at the specified dates and time. I'm only concerned about the efficiency of this in production with a lot of users scheduling all kinds of messages at different dates and times.
So, Is this fine in production or do I need to make changes?