0

I have a MySQL database that contains records with an expiresAt timestamp. When this timestamp is reached, I want to execute some code to update the record.

I've considered using a background worker process with a cron job to periodically check for expired records, but I'm not sure if this is the most efficient approach. I've also heard about database triggers and MySQL events, but I'm not sure how to implement them using PlanetScale.

What are some best practices and recommended approaches for executing code when a timestamp is reached in a MySQL database hosted on PlanetScale using Prisma and Node.js?

altsphaantm
  • 11
  • 1
  • 2
  • What do you think *wouldn't* be efficient about a cron job? To give you more accurate information we'd have to know more specifics about the nature of your application: how many of these records you will have, how frequently you want to check for updates, how many you want to batch update at a time, what the size of the DB is, what the load on the DB is at any time (maybe you want to run the updates when loads are lower, like at night?), how long it takes to update each record (i.e. what calculations are required and what kind of load *that* puts on the DB). – kmoser Apr 15 '23 at 21:42
  • I wonder if there is something similar to Webhooks <-> polling where polling would result in a lot of executions even when there is no activity at all and webhooks are more efficient Same would apply to constantly checking if records with expiresAt < now() exist. I am mostly interested in reducing unnecessary executions when possible. – altsphaantm Apr 15 '23 at 21:52

0 Answers0