As CPAN perldoc says: reliable job queue. Basically it splitted into two parts, one is worker while the other is client.I
Worker script:
We may have several workers to deal with different tasks. For example TheSchwartz_worker.pl deal with some tasks while TheSchwartz_worker_scraper.pl deal with scraper task.
What's worker for? In my idea, that's just a script to monitor a table in database (check if there is any task to do) every 5 secs. Faked code like this:
while (1) { # check if there is any new TODO task in one table of theschwartz database. if ($has_new_task) { # scalar @new_tasks foreach my $new_task (@new_tasks) { $new_task->worker(); } } sleep 5;
Where does new task from? Foorum has two ways, always one is form Foorum/Controller|Model, the other is from cron scripts.
example code:
use Foorum::ExternalUtils qw/theschwartz/; my $client = theschwartz(); $client->insert( 'Foorum::TheSchwartz::Worker::WorkerExample', @args );
That's a simple introduction. Maybe I'm wrong here. :)
For now, we have several workers:
There is a simple RULES that why we use TheSchwartz, put heavy code on backend script instead of httpd.
OK, please borrow code from exist ones.
Get the lastest version from http://code.google.com/p/foorum/wiki/Tutorial2