Dobrica Pavlinušić's random unstructured stuff
Gearman: Revision 2


Links

Implementations

Documentation

Cookbook

  • gearman

    0.install.sh

    gearman/0.install.sh
    apt-get install libgearman-client-perl

    gearman.pl

    • simple perl command-line client depenent only on libgearman-client-perl which is in etch 2010-05-01 12:49
    gearman/gearman.pl
    #!/usr/bin/perl
    
    use warnings;
    use strict;
    
    use Data::Dump qw(dump);
    use Getopt::Long;
    use Gearman::Worker;
    
    my $host = '10.60.0.244:4730';
    my $function = 'test';
    
    GetOptions(
    	'host' => \$host,
    	'function' => \$function,
    ) || die $!;
    
    
    my $worker = Gearman::Worker->new;
    $worker->job_servers( $host );
    $worker->register_function( $function => sub {
    	my $job = $_[0];
    	my $arg = $_[0]->arg;
    	warn "# job ",dump($job);
    });
    warn "# worker ",dump($worker);
    $worker->work while 1;
    
    =for client
    
    my $client = Gearman::Client->new;
    $client->job_servers($host);
    
    # running a single task
    my $result_ref = $client->do_task("add", "1+2");
    print "1 + 2 = $$result_ref\n";
    
    # waiting on a set of tasks in parallel
    my $taskset = $client->new_task_set;
    $taskset->add_task( "add" => "1+2", {
    	on_complete => sub { ... }
    });
    
    $taskset->add_task( "divide" => "5/0", {
    	on_fail => sub { print "divide by zero error!\n"; },
    });
    $taskset->wait;
    
    =cut

    grep_logs.sh

    gearman/grep_logs.sh
    #!/bin/sh -x
    
    # echo 'error' | gearman -f grep_logs
    
    if [ -z "$1" ] ; then
    	hostname=`hostname`
    	exec /srv/gearmand/bin/gearman -h 10.60.0.244 -w -f grep_$hostname $0 $hostname
    fi
    
    read pattern
    grep $pattern /var/log/*.log