This post is half-this is how you do it, and half-is there a
better way to do it?
So you want to build a system that does jobs. You want the jobs
to be able to be run in parallel for speed, but also for
redundancy. This system needs to be coordinated so, for example,
the same jobs aren't being done twice, the status of every job is
easy to see, and multiple servers can run jobs by simply querying
the central source.
How can we build code around Innodb to have MySQL be our central
controlling scheme?
CREATE TABLE IF NOT EXISTS job_queue(
id int(10) not null auto_increment,
updated timestamp not null,
started timestamp not null,
state ENUM('NEW', 'WORKING', 'DONE', 'ERROR' ) default 'NEW',
PRIMARY KEY ( id ),
KEY( STATE )
) ENGINE=Innodb;
In this schema, our job table has a unique id, started and last
updated …