Obviously you can use a database for this. It might be overkill though, but using transactions and the right isolation level can make for a very nice queue.
I guess an alternative is to have a directory that is used for locking. The directory would contain a mutex lock file that is used to show that a job is already running as well as a file per job queued up (you could use numeric increasing filenames to ensure the jobs are processed in order.) The process would look like this:
- Process starts, tries to get lock on mutex file.
-
If the lock is obtained the directory is scanned for job files. If job files exist then the path the process was originally tasked to perform is written to the directory as a job file and the first job in the queue is performed.
-
If the lock fails then there is already a task running, so simply write a job file and exit.
-
Directory is processed.
-
Job file is deleted.
-
Prior to termination and the relinquishing of the lock the process rescans for pending job files. If any are present it processes them in order until there are no jobs pending.
Anyway, thats probably what i would do if I wansnt going to to use a DB.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.