File: Gearman.pm

package info (click to toggle)
libanyevent-gearman-perl 0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 440 kB
  • ctags: 499
  • sloc: perl: 5,892; makefile: 2
file content (117 lines) | stat: -rw-r--r-- 2,413 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package AnyEvent::Gearman;
use strict;
use warnings;
use base 'Exporter';

our $VERSION = '0.10';

our @EXPORT = qw/gearman_client gearman_worker/;

use AnyEvent::Gearman::Client;
use AnyEvent::Gearman::Worker;

sub gearman_client {
    AnyEvent::Gearman::Client->new(
        job_servers => [@_],
    );
}

sub gearman_worker {
    AnyEvent::Gearman::Worker->new(
        job_servers => [@_],
    );
}

1;

__END__

=head1 NAME

AnyEvent::Gearman - Asynchronous Gearman client/worker module for AnyEvent applications

=head1 SYNOPSIS

    use AnyEvent::Gearman;

Client:

    my $client = gearman_client '127.0.0.1', '192.168.0.1:123';
    
    $client->add_task(
        $function => $workload,
        on_complete => sub {
            my $result = $_[1];
            # ...
        },
        on_fail => sub {
            # job failed
        },
    );

Worker:

    my $worker = gearman_worker '127.0.0.1', '192.168.0.1:123';
    
    $worker->register_function(
        reverse => sub {
            my $job = shift;
            my $res = reverse $job->workload;
            $job->complete($res);
        },
    );

=head1 DESCRIPTION

AnyEvent::Gearman is a module set of client/worker modules for Gearman for AnyEvent applications.

This module provides some shortcuts for L<AnyEvent::Gearman::Client> and L<AnyEvent::Gearman::Worker>.
Please read these modules documentation for more details.

=head1 EXPORTED FUNCTIONS

=head2 gearman_client( @job_servers );

Create a gearman client.

    my $client = gearman_client '127.0.0.1', '192.168.0.1:123';

This is shortcut for:

    my $client = AnyEvent::Gearman::Client->new(
        job_servers => ['127.0.0.1', '192.168.0.1:123'],
    );

See L<AnyEvent::Gearman::Client> for more detail.

=head2 gearman_worker( @job_servers );

Create a gearman worker.

    my $worker = gearman_worker '127.0.0.1', '192.168.0.1:123';

This is shortcut for:

    my $worker = AnyEvent::Gearman::Worker->new(
        job_servers => ['127.0.0.1', '192.168.0.1:123'],
    );

See L<AnyEvent::Gearman::Worker> for more detail.

=head1 AUTHOR

Daisuke Murase <typester@cpan.org>

Pedro Melo <melo@cpan.org>

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2009 by KAYAC Inc.

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

The full text of the license can be found in the
LICENSE file included with this module.

=cut