| 1 | package Gearman::Job; | ||||||||||
| 2 | 12 | ▶ | use version (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 12 | $Gearman::Job::VERSION = version->declare("2.004.015"); | |||||||||
| 4 | |||||||||||
| 5 | 12 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 12 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 12 | ▶ | use Gearman::Util (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 12 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | =head1 NAME | ||||||||||
| 12 | |||||||||||
| 13 | Gearman::Job - Job in gearman distributed job system | ||||||||||
| 14 | |||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | I<Gearman::Job> is the object that's handed to the worker subrefs | ||||||||||
| 19 | |||||||||||
| 20 | =head1 METHODS | ||||||||||
| 21 | |||||||||||
| 22 | =cut | ||||||||||
| 23 | |||||||||||
| 24 | 12 | ▶ | use fields ( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 12 | 'func', | |||||||||
| 26 | 'argref', | ||||||||||
| 27 | 'handle', | ||||||||||
| 28 | |||||||||||
| 29 | # job server's socket | ||||||||||
| 30 | 'jss', | ||||||||||
| 31 | |||||||||||
| 32 | # job server | ||||||||||
| 33 | 'js', | ||||||||||
| 34 | 12 | ); | |||||||||
| 35 | |||||||||||
| 36 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 37 | 1 | my ($self, %arg) = @_; | |||||||||
| 38 | 1 | ▶ | unless (ref $self) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 1 | $self = fields::new($self); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 1 | ▶ | while(my ($k, $v) = each(%arg)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 5 | $self->{$k} = $v; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 1 | return $self; | |||||||||
| 47 | } ## end sub new | ||||||||||
| 48 | |||||||||||
| 49 | =head2 set_status($numerator, $denominator) | ||||||||||
| 50 | |||||||||||
| 51 | Updates the status of the job (most likely, a long-running job) and sends | ||||||||||
| 52 | it back to the job server. I<$numerator> and I<$denominator> should | ||||||||||
| 53 | represent the percentage completion of the job. | ||||||||||
| 54 | |||||||||||
| 55 | =cut | ||||||||||
| 56 | |||||||||||
| 57 | 1 | ▶ | sub set_status { | ||||||||
|
Subroutine
set_status: called CC=2 SCAR=8.4
Pod
documented
| |||||||||||
| 58 | 1 | my $self = shift; | |||||||||
| 59 | 1 | my ($nu, $de) = @_; | |||||||||
| 60 | |||||||||||
| 61 | my $req = Gearman::Util::pack_req_command("work_status", | ||||||||||
| 62 | 1 | join("\0", $self->{handle}, $nu, $de)); | |||||||||
| 63 | |||||||||||
| 64 | Carp::croak "work_status write failed" | ||||||||||
| 65 | 1 | ▶ | unless Gearman::Util::send_req($self->{jss}, \$req); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | |||||||||||
| 67 | 0 | return 1; | |||||||||
| 68 | } ## end sub set_status | ||||||||||
| 69 | |||||||||||
| 70 | =head2 argref() | ||||||||||
| 71 | |||||||||||
| 72 | =cut | ||||||||||
| 73 | |||||||||||
| 74 | 1 | ▶ | sub argref { | ||||||||
|
Subroutine
argref: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 75 | 1 | return shift->{argref}; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | =head2 arg() | ||||||||||
| 79 | |||||||||||
| 80 | B<return> the scalar argument that the client sent to the job server. | ||||||||||
| 81 | |||||||||||
| 82 | =cut | ||||||||||
| 83 | |||||||||||
| 84 | 1 | ▶ | sub arg { | ||||||||
|
Subroutine
arg: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 85 | 1 | return ${ shift->{argref} }; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | =head2 handle() | ||||||||||
| 89 | |||||||||||
| 90 | B<return> handle | ||||||||||
| 91 | |||||||||||
| 92 | =cut | ||||||||||
| 93 | |||||||||||
| 94 | 1 | ▶ | sub handle { | ||||||||
|
Subroutine
handle: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 95 | 1 | return shift->{handle}; | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | 12 | 1; | |||||||||