line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Job::Async::Worker; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
688
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
47
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
42
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
9
|
use parent qw(IO::Async::Notifier); |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
10
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.004'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Job::Async::Worker - worker API for L |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This is the thing that receives jobs, does the work, and sends |
17
|
|
|
|
|
|
|
back a result. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
2
|
|
878
|
use Ryu::Async; |
|
2
|
|
|
|
|
207406
|
|
|
2
|
|
|
|
|
65
|
|
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
424
|
use Job::Async::Job; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
485
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub jobs { |
30
|
2536
|
|
|
2536
|
0
|
3943
|
my ($self) = @_; |
31
|
2536
|
|
66
|
|
|
8025
|
$self->{jobs} ||= do { |
32
|
2
|
|
|
|
|
23
|
$self->ryu->source( |
33
|
|
|
|
|
|
|
label => 'jobs' |
34
|
|
|
|
|
|
|
) |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
0
|
0
|
0
|
0
|
sub id { shift->{id} //= Job::Async::Utils::uuid() } |
39
|
0
|
|
|
0
|
0
|
0
|
sub timeout { shift->{timeout} } |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub configure { |
42
|
2
|
|
|
2
|
1
|
5110
|
my ($self, %args) = @_; |
43
|
2
|
|
|
|
|
6
|
for my $k (qw(id timeout)) { |
44
|
4
|
50
|
|
|
|
14
|
$self->{$k} = delete $args{$k} if exists $args{$k}; |
45
|
|
|
|
|
|
|
} |
46
|
2
|
|
|
|
|
15
|
return $self->next::method(%args); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub stop { |
50
|
1
|
|
|
1
|
0
|
526
|
my ($self) = @_; |
51
|
1
|
|
|
|
|
3
|
my $f = $self->jobs->completed; |
52
|
1
|
50
|
|
|
|
7
|
$f->done unless $f->is_ready; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub ryu { |
56
|
2
|
|
|
2
|
0
|
6
|
my ($self) = @_; |
57
|
2
|
|
33
|
|
|
8
|
$self->{ryu} ||= do { |
58
|
2
|
|
|
|
|
17
|
$self->add_child( |
59
|
|
|
|
|
|
|
my $ryu = Ryu::Async->new |
60
|
|
|
|
|
|
|
); |
61
|
2
|
|
|
|
|
185
|
$ryu; |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 AUTHOR |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Tom Molesworth |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 LICENSE |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Copyright Tom Molesworth 2016-2017. Licensed under the same terms as Perl itself. |
74
|
|
|
|
|
|
|
|