I am trying to achieve the following… wondering if there is any way to
- i have an application where the user can request an specific email to
be sent at a scheduled time. For e.g. lets say user A wants is
scheudling the email to be sent for 12:00pm. This is stored in a table
called “send_notification” where the details is stored.
- Another user B can login and schedule an notification say at 11:45am.
Now, to achieve this…
If can have a background task that scans through this table and sends
the notification. But if i write it as a task that wakes up every minute
and send the notification, then it has to scan the whole table every
time. Is it OK ?. In a scaled table it could be an issue.
Maintain a “earliest time” variable in the application. Every time, a
new notification is created, check if this time is earlier than the
“earliest time”. If so, then cancel the crontab and reschedule based on
the “earliest time”. If not, the crontab will expire and notification
will be sent and scan the whole table and update the “earliest time”.
This again has the flaw of scanning the entire table.
an efficient option is to maintain a heap timer tree based on “shcedule
time”. Then the top node timer expires, the notification will be sent.
This would require no scanning of table but maintaining the heap timer.
Is a there a plugin for this ?.
How does typcially achieve such a thing.