Suppose you have to implement a schedule broadcasting to users in their application (like WhatsApp, Line). The data will send from the client (via HTML form) here the logics are,
- If
isSchedule === false
then save the message to the database and broadcast right now. - If
isSchedule === true
then save the message to the database and wait until time reach and send the message.
How to trigger the database when the time is reaching?
The solution that appears in my mind is using cron job
by retrieving data from the database every minute and check with Date.now()
if timeInDB - Date.now() < 0
then just broadcast message to the user. But I'm not sure it a good solution to retrieving data every minute? Please see the diagram below, thank you.
Aucun commentaire:
Enregistrer un commentaire