dimanche 27 septembre 2020

Create schedule broadcast API with node.js and Mongodb

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,

  1. If isSchedule === false then save the message to the database and broadcast right now.
  2. 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. enter image description here

Aucun commentaire:

Enregistrer un commentaire