Due to performance issues arising from row locking and a long running query in a trigger, I’ve opted to instead run the query as a stored procedure from a cron job every five minutes.
My problem is that I need to prevent the situation where the query takes longer than 5 minutes and collides with the next scheduled run of the stored procedure. Since I do run this query in transaction, ideally I’d just execute a rollback somewhere in the stored procedure once the five minutes were up. Is this possible?
Thanks.
The ‘brute force’ method would be to have a table with ‘jobs’. Each row would have a start time and end time. Look for the most recent start time that doesn’t have an end time. If your next job wants to start and there isn’t an end time listed then kill the previous job.
You could even put the process id in there.