Giter VIP home page Giter VIP logo

p5-mediacloud-jobmanager's Introduction

Build Status Coverage Status

MediaCloud::JobManager

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

Features

Sample

Worker

package AddTwoNumbers;

use strict;
use warnings;

use Moose;
with 'MediaCloud::JobManager::Job';

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

use AddTwoNumbers;

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

Installing

OS X doesn't provide OpenSSL headers required by Net::AMQP::RabbitMQ, so before installing this module run:

# Install OpenSSL from Homebrew which provides required headers
brew install openssl

# Make Net::AMQP::RabbitMQ's Makefile look for OpenSSL headers in /usr/local/opt/openssl;
# also, remove MACOSX_DEPLOYMENT_TARGET from LD and use just "cc"
export PERL_MM_OPT='CCFLAGS="-I/usr/local/opt/openssl/include" LDFLAGS="-L/usr/local/opt/openssl/lib" LD="env cc"'

Code formatting

Install perltidy Git hook to automatically fix script formatting:

cpanm --installdeps .
githook-perltidy install

p5-mediacloud-jobmanager's People

Contributors

neilb avatar pypt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.