Queue::Worker - Database based work queue abstraction.


Queue-Worker documentation  | view source Contained in the Queue-Worker distribution.

Index


NAME

Top

Queue::Worker - Database based work queue abstraction.

SYNOPSIS

Top

    package MyWorker;
    use base 'Queue::Worker';

    sub name { 'my_work'; }

    sub process {
            my ($self, $item) = @_;
            # do your work here
    }

    # create worker table in db
    MyWorker->create_table($dbh);

    # and somewhere else
    MyWorker->enqueue($dbh, 'some work order string');

    # and finally to run the queue
    MyWorker->run($dbh);

DESCRIPTION

Top

This module provides simple, database queue based, worker abstraction. It provides locking between worker instances using POSIX::RT::Semaphore.

Strings representing work orders are enqueued with enqueue function. Those items are removed from the queue by run function.

METHODS

Top

$class->create_table($dbh, $name)

Creates table queue_worker_$name table in the database. $name parameter is optional: if undef name accessor is used.

$class->enqueue($dbh, $msg)

Enqueues work order $msg into the queue.

$class->new

Creates new instance of the worker. Also creates underlying semaphore.

$class->run($dbh)

Runs the queue. Calls process method on each work item.

$class->get_semaphore

Returns underlying semaphore.

ABSTRACT METHODS

Top

The following methods should be implemented by inherited class.

$class->name

Should return the name of the worker.

$self->process($msg)

Callback to process the work order.

AUTHOR

Top

	Boris Sukholitko
	CPAN ID: BOSU

	boriss@gmail.com




COPYRIGHT

Top

SEE ALSO

Top

POSIX::RT::Semaphore


Queue-Worker documentation  | view source Contained in the Queue-Worker distribution.