View Single Post

   
  #4 (permalink)  
Old 03-06-2008, 03:04 PM
--CELKO--
 
Posts: n/a
Default Re: Queue handling design pattern?

> For now I have a single table with an IDENTITY column [sic: table property] and some information about what to do. Combined with multiple jobs "eating" from queue <<

If you really want to mimic a queue in SQL for some strange reason,
then get out an old book on batch systems from the 1970's. You can
mimic them with a little effort:

CREATE TABLE Queue
(job_nbr INTEGER NOT NULL PRIMARY KEY,
job_submission_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
job_priority INTEGER DEFAULT 100 NOT NULL,
etc.);

You pick the job to run with something like this:

SELECT job_nbr, ...
FROM Queue AS Q1
WHERE Q1.job_nbr
= (SELECT MIN(job_nbr)
FROM Queue AS Q2
WHERE Q2.job_priority
=(SELECT MIN(Q3.job_priority)
FROM Queue AS Q3));

Every now and then, run a procedure that decrements the job_priority
of rows that have been in the queue for over (n) seconds until it is
zero and will be done next. If you want to force a job to the top of
the queue, insert it with a low (non-zero) job_priority value.
Remember to delete the jobs as they are processed. It is easy to see
that all jobs will clear the queue.

Reply With Quote