Reputation: 11
I am developing a parking system web application, where users can book parking slots. I have two tables in my database:
accounts (userID, username, Registration_plate_num,email,phone_num)
tickets (ticketID*,startingDate_time,endingDate_time,userID)
I would like to update my tickets table in away that every few minutes I check in the table to see if I find a ticket whose endingDate_time is actually smaller than "current" date_time, which implies that this ticket has been expired and is not longer needed in the database and should be removed.
Now, I would like to run this SQL query function in the **background ** as soon as I start running my web server. I have no problem in writing such as function, however, I am confused on where I meant to write the function So it runs in parallel with my web application.
I would really appreciate if i could get some guidance on how I could run this query in parallel, so once the server has started, the SQL query function gets called every few minutes and deletes the tickets that have been expired.
Thank you.
Upvotes: 1
Views: 647
Reputation: 25763
It would probably be best to NOT tie this to your web application.
Some reasonings are:
Instead, a few options may be a better choice:
If your scheduled task is going to be 100% database changes, and nothing else (such as sending emails, invoking APIs, etc.) then the database CRON job may be the most robust and simplest option.
Upvotes: 1