Gearman-JobScheduler
view release on metacpan or search on metacpan
lib/Gearman/JobScheduler/AbstractFunction.pm view on Meta::CPAN
=head1 NAME
C<Gearman::JobScheduler::AbstractFunction> - An abstract class for a Gearman
"function" which is to be derived by working Gearman "functions".
=head1 LINGO
=over 4
=item * Gearman function
A function to be run by Gearman or locally, e.g. C<add_default_feeds>.
=item * Gearman job
An instance of the Gearman function doing the actual job with specific parameters.
=back
=cut
package Gearman::JobScheduler::AbstractFunction;
use strict;
use warnings;
use Modern::Perl "2012";
use feature qw(switch);
use Moose::Role 2.1005;
use Gearman::JobScheduler; # helper subroutines
use Gearman::JobScheduler::Configuration;
use Gearman::JobScheduler::ErrorLogTrapper;
use Gearman::XS qw(:constants);
use Gearman::XS::Client;
use Gearman::XS::Task;
use Gearman::XS::Worker;
use IO::File;
use Capture::Tiny ':all';
use Time::HiRes;
use Data::Dumper;
use DateTime;
use File::ReadBackwards;
use Readonly;
use Sys::Hostname;
# used for capturing STDOUT and STDERR output of each job and timestamping it;
# initialized before each job
use Log::Log4perl qw(:easy);
=head1 ABSTRACT INTERFACE
The following subroutines must be implemented by the subclasses of this class.
=head2 REQUIRED
=head3 C<run($self, $args)>
Run the job.
Parameters:
=over 4
=item * C<$self>, a reference to the instance of the Gearman function class
=item * (optional) C<$args> (hashref), arguments needed for running the
Gearman function
=back
An instance (object) of the class will be created before each run. Class
instance variables (e.g. C<$self-E<gt>_my_variable>) will be discarded after
each run.
Returns result on success (serializable by the L<JSON> module). The result
will be discarded if the job is ordered on Gearman as a background process.
Provides progress reports when available:
=over 4
=item * by calling C<$self-E<gt>set_progress($numerator, $denominator)>
( run in 0.421 second using v1.01-cache-2.11-cpan-fe3c2283af0 )