Using MySQL as a job queue

Posted by user237815 on Stack Overflow See other posts from Stack Overflow or by user237815
Published on 2011-08-11T18:04:52Z Indexed on 2012/03/24 5:29 UTC
Read the original article Hit count: 187

Filed under:
|
|
|

I'd like to use MySQL as a job queue. Multiple machines will be producing and consuming jobs. Jobs need to be scheduled; some may run every hour, some every day, etc.

It seems fairly straightforward: for each job, have a "nextFireTime" column, and have worker machines search for the job with the nextFireTime, change the status of the record to "inProcess", and then update the nextFireTime when the job ends.

The problem comes in when a worker dies silently. It won't be able to update the nextFireTime or set the status back to "idle".

Unfortunately, jobs can be long-running, so a reaper thread that looks for jobs that have been inProcess too long isn't an option. There's no timeout value that would work.

Can anyone suggest a design pattern that would properly handle unreliable worker machines?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about algorithm