I have a cron job running every few minutes that goes through the first 50 items on a 'to do' list, runs a script on each item and marks it as run in the database.
This was working well until the table that marks off the item as complete got locked by something and the items didnt get marked off. Then the cron ran again and went through the same 50 items.
This repeated and repeated until the process list in mysql was massive and only getting larger by 50 every few mins.
How could i stop this happenning? my thoughts would be:
- Add code to the script to see if the cron is still running before running again
- check the mysql table for the locked table before running the new SELECT query to get the next 50 items
They both seem to have ups and downs and i am not sure how to implement either properly. Anyone have any advice / better ideas?