line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Job::Async::Worker; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
821
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
63
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
21
|
use parent qw(IO::Async::Notifier); |
|
2
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
12
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.003'; # 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
|
|
1069
|
use Ryu::Async; |
|
2
|
|
|
|
|
248351
|
|
|
2
|
|
|
|
|
72
|
|
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
585
|
use Job::Async::Job; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
568
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub jobs { |
30
|
2536
|
|
|
2536
|
0
|
4955
|
my ($self) = @_; |
31
|
2536
|
|
66
|
|
|
9924
|
$self->{jobs} ||= do { |
32
|
2
|
|
|
|
|
27
|
$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
|
5863
|
my ($self, %args) = @_; |
43
|
2
|
|
|
|
|
8
|
for my $k (qw(id timeout)) { |
44
|
4
|
50
|
|
|
|
13
|
$self->{$k} = delete $args{$k} if exists $args{$k}; |
45
|
|
|
|
|
|
|
} |
46
|
2
|
|
|
|
|
17
|
return $self->next::method(%args); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub stop { |
50
|
1
|
|
|
1
|
0
|
643
|
my ($self) = @_; |
51
|
1
|
|
|
|
|
3
|
my $f = $self->jobs->completed; |
52
|
1
|
50
|
|
|
|
8
|
$f->done unless $f->is_ready; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub ryu { |
56
|
2
|
|
|
2
|
0
|
7
|
my ($self) = @_; |
57
|
2
|
|
33
|
|
|
8
|
$self->{ryu} ||= do { |
58
|
2
|
|
|
|
|
14
|
$self->add_child( |
59
|
|
|
|
|
|
|
my $ryu = Ryu::Async->new |
60
|
|
|
|
|
|
|
); |
61
|
2
|
|
|
|
|
220
|
$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
|
|
|
|
|
|
|
|