Reputation: 13
I am currently making a application to track an items expiry date. I am using firebase to store data about the item such as, name, amount, date until expired. Is it possible to add a count down timer to a corresponding item. So if I enter an item with a expiry of 2 days the timer will start to count down from 2 days in real time. Is this possible to do? If so what would the best way to go about this problem?
Thanks
Upvotes: 0
Views: 636
Reputation: 2222
You didn't mention if you'd like to do this countdown on the client side or "server"(less?) side, but I'd say instead of relying on the client browser to be open for 3 days, you can do this on the server(less) side.
I ran into the same problem just recently, and here's how I ended up solving this.
Step 1 : Create a node in your database based on dates like :
May 1 2017 (or even as specific as 05-01-2017-11:00EST if you want to expire things hourly)
May 15 2017
Step 2
Either set up a mini VPS/Server somewhere to run cron tasks that fire http triggers or pub/sub triggers to engage a Firebase Cloud Function
Or use AWS Lambda with Scheduled Events to periodically check your expiry list on Firebase database.
This way you can keep a log of what expired when, and also take action based on these daily / hourly. As long as your servers are in some form of a time-sync, you can check your expiry list very selectively too (like check only May 5th 11am) etc.
Also, here is a tutorial & a post about what you're looking for.
Another question / answer from SOF
Hope this helps :)
Upvotes: 1