Build Status Coverage Status

MediaCloud::JobManager

(Yet another) Perl worker / client library for running jobs asynchronously.

Features

Sample

Worker

package AddTwoNumbers;
use strict;
use Moose;
sub run($;$)
{
my ( $self, $args ) = @_;
my $number_1 = $args->{ number_1 };
my $number_2 = $args->{ number_2 };
# Write the sum to the database here
say STDERR "Sum: " . ( $number_1 + $number_2 );
return 1;
}
no Moose; # gets rid of scaffolding
# Return package name instead of 1 or otherwise worker.pl won't know the
# name of the package it's loading
__PACKAGE__;

Client

my $args = { number_1 => 3, number_2 => 4 };
# Run locally, like any other function
AddTwoNumbers->run_locally( $args );
# Run remotely, wait for the function to finish
AddTwoNumbers->run_remotely( $args );
# Add to broker's queue and return instantly, don't wait for the function to finish
AddTwoNumbers->add_to_queue( $args );

Development Notes

Code formatting

Install perltidy Git hook to automatically fix script formatting:

cpanm --installdeps .
githook-perltidy install