line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::Gearman::Client; |
2
|
6
|
|
|
6
|
|
13933
|
use Any::Moose; |
|
6
|
|
|
|
|
375979
|
|
|
6
|
|
|
|
|
45
|
|
3
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
11233
|
use AnyEvent::Gearman::Types; |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
203
|
|
5
|
6
|
|
|
6
|
|
6416
|
use AnyEvent::Gearman::Task; |
|
6
|
|
|
|
|
1197
|
|
|
6
|
|
|
|
|
271
|
|
6
|
6
|
|
|
6
|
|
6426
|
use AnyEvent::Gearman::Client::Connection; |
|
6
|
|
|
|
|
620
|
|
|
6
|
|
|
|
|
604
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has job_servers => ( |
9
|
|
|
|
|
|
|
is => 'rw', |
10
|
|
|
|
|
|
|
isa => 'AnyEvent::Gearman::Client::Connections', |
11
|
|
|
|
|
|
|
required => 1, |
12
|
|
|
|
|
|
|
coerce => 1, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has prefix => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
isa => 'Str', |
18
|
|
|
|
|
|
|
default => '', |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
6
|
|
|
6
|
|
4075
|
no Any::Moose; |
|
6
|
|
|
|
|
217
|
|
|
6
|
|
|
|
|
206
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub add_task { |
24
|
11
|
|
|
11
|
1
|
57227
|
my $self = shift; |
25
|
|
|
|
|
|
|
|
26
|
11
|
|
|
|
|
94
|
return $self->_add_task('', @_) |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub add_task_bg { |
30
|
1
|
|
|
1
|
1
|
43
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
7
|
return $self->_add_task('bg', @_) |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _add_task { |
36
|
12
|
|
|
12
|
|
408
|
my ($self, $type, $function, $workload, %cb) = @_; |
37
|
|
|
|
|
|
|
|
38
|
12
|
100
|
|
|
|
126
|
$function = $self->prefix . "\t" . $function |
39
|
|
|
|
|
|
|
if $self->prefix; |
40
|
|
|
|
|
|
|
|
41
|
12
|
|
|
|
|
532
|
my $task = AnyEvent::Gearman::Task->new( $function, $workload, %cb ); |
42
|
|
|
|
|
|
|
|
43
|
12
|
|
|
|
|
20138
|
my $retry; ($retry = sub { |
44
|
12
|
|
|
12
|
|
35
|
my @js = grep { $_->alive } @{ $self->job_servers }; |
|
12
|
|
|
|
|
395
|
|
|
12
|
|
|
|
|
86
|
|
45
|
|
|
|
|
|
|
|
46
|
12
|
50
|
|
|
|
53
|
unless (@js) { |
47
|
0
|
|
|
|
|
0
|
$task->event( on_fail => 'no server available' ); |
48
|
0
|
|
|
|
|
0
|
undef $retry; |
49
|
0
|
|
|
|
|
0
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# TODO: hashed server selector |
53
|
12
|
|
|
|
|
73
|
my $js = @js[int rand @js]; |
54
|
|
|
|
|
|
|
$js->add_task( |
55
|
|
|
|
|
|
|
$task, |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# task added successfully |
58
|
|
|
|
|
|
|
sub { |
59
|
11
|
|
|
|
|
56
|
undef $retry; |
60
|
|
|
|
|
|
|
}, |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# on error |
63
|
12
|
|
|
|
|
139
|
$retry, |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# task type |
66
|
|
|
|
|
|
|
$type, |
67
|
|
|
|
|
|
|
); |
68
|
12
|
|
|
|
|
168
|
})->(); |
69
|
|
|
|
|
|
|
|
70
|
12
|
|
|
|
|
137
|
$task; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |