line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Job::Async::Worker; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
687
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
44
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
40
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
7
|
use parent qw(IO::Async::Notifier); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
8
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.002'; # 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
|
|
829
|
use Ryu::Async; |
|
2
|
|
|
|
|
194694
|
|
|
2
|
|
|
|
|
56
|
|
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
422
|
use Job::Async::Job; |
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
463
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub jobs { |
30
|
2536
|
|
|
2536
|
0
|
3719
|
my ($self) = @_; |
31
|
2536
|
|
66
|
|
|
8335
|
$self->{jobs} ||= do { |
32
|
2
|
|
|
|
|
7
|
$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
|
4832
|
my ($self, %args) = @_; |
43
|
2
|
|
|
|
|
5
|
for my $k (qw(id timeout)) { |
44
|
4
|
50
|
|
|
|
12
|
$self->{$k} = delete $args{$k} if exists $args{$k}; |
45
|
|
|
|
|
|
|
} |
46
|
2
|
|
|
|
|
12
|
return $self->next::method(%args); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub stop { |
50
|
1
|
|
|
1
|
0
|
457
|
my ($self) = @_; |
51
|
1
|
|
|
|
|
3
|
my $f = $self->jobs->completed; |
52
|
1
|
50
|
|
|
|
6
|
$f->done unless $f->is_ready; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub ryu { |
56
|
2
|
|
|
2
|
0
|
5
|
my ($self) = @_; |
57
|
2
|
|
33
|
|
|
6
|
$self->{ryu} ||= do { |
58
|
2
|
|
|
|
|
20
|
$self->add_child( |
59
|
|
|
|
|
|
|
my $ryu = Ryu::Async->new |
60
|
|
|
|
|
|
|
); |
61
|
2
|
|
|
|
|
201
|
$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
|
|
|
|
|
|
|
|