NAME

Job::Machine::Worker - Base class for Job Workers

DESCRIPTION

  Inherits from Job::Machine::Base.
  
  All you have to do to write a worker for a particular Job Class is
  
  use base 'Job::Machine::Worker';

  sub process {
	  my ($self, $task) = @_;
	  ... do stuff
  };

METHODS

Methods to be subclassed

A worker process always needs to subclass the process method with the real functionality.

startup

startup will be called before any tasks are fetched and any processing is done.

Call this method for one-time initializing.

process

 Subclassable process method.

 E.g. 

 sub process {
	my ($self, $data) = @_;
	... process $data 
	$self->reply({answer => 'Something'});
 };

max_runtime

If the default of 30 minutes isn't suitable, return the number of seconds a process is allowed to run.

timeout

If the default of 5 minutes isn't suitable, return the number of seconds the worker should wait for inout before doing housekeeping chores.

If you don't want the worker to perform any housekeeping tasks, return undef

retries

If the default of 3 times isn't suitable, return the number of times a task is retried before failing.

keep_running

Worker will wait for next message if this method returns true.

Methods to be used from within the process method

reply

$worker->reply($some_structure);

Reply to a message. Use from within a Worker's process method.

result

$worker->result($result_data);

Save the result of the task. Use from within a Worker's process method.

db

Get the DB class. From this it's possible to get the database handle

my $dbh = $self->db->dbh;

If you use the same database for Job::Machine as for your other data, this
handle can be used by your worker module.

id

methods not to be disturbed

receive

$worker->receive;

Starts the Worker's receive loop.

receive subscribes the worker to the queue and waits for a message to be passed along.
It will first see if there are any messages to be processed.

SEE ALSO

Job::Machine::Base.

AUTHOR

Kaare Rasmussen <kaare@cpan.org>.

COPYRIGHT

Copyright (C) 2009-2010, Kaare Rasmussen

This module is free software; you can redistribute it or modify it under the same terms as Perl itself.