Application data update at a particular time

I have an application which take data from a database. I want to update data at a particular time of day like 9 am. How can I do it?

1 Like

hi @Nimaano
I’ve never tried this but one way I’m thinking could work is you read the time every minute (with the dcc.Interval triggering a callback once a minute):

import datetime
current_time = datetime.datetime.now()

Then, if the current_time is between 8:59 to 9:01 you pull data from the database.

The simplest option would probably be to implement a cache, and invalidate the cache at 9 am. That would make the first callback after 9 am fetch new data (it would thus be slow), which will then be reused for subsequent requests.

If you need the data updated before the first callback (after 9 am), you would need to schedule a job to do so. It could be e.g. through Celery, cron, Flask, or FastAPI. The best choice depends on your needs and existing infrastructure.

1 Like