line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Job::Manager::Worker; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Job::Manager::Worker::VERSION = '0.16'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
1
|
|
|
1
|
|
2311
|
$Job::Manager::Worker::AUTHORITY = 'cpan:TEX'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: baseclass for any Worker managed by Job::Manager |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
28
|
use 5.010_000; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
11
|
1
|
|
|
1
|
|
6
|
use mro 'c3'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
12
|
1
|
|
|
1
|
|
32
|
use feature ':5.10'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
103
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
465
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use namespace::autoclean; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# use IO::Handle; |
18
|
|
|
|
|
|
|
# use autodie; |
19
|
|
|
|
|
|
|
# use MooseX::Params::Validate; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Sys::Run; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has 'config' => ( |
24
|
|
|
|
|
|
|
'is' => 'ro', |
25
|
|
|
|
|
|
|
'isa' => 'Config::Yak', |
26
|
|
|
|
|
|
|
'required' => 0, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has 'logger' => ( |
30
|
|
|
|
|
|
|
'is' => 'rw', |
31
|
|
|
|
|
|
|
'isa' => 'Log::Tree', |
32
|
|
|
|
|
|
|
'required' => 1, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has 'sys' => ( |
36
|
|
|
|
|
|
|
'is' => 'rw', |
37
|
|
|
|
|
|
|
'isa' => 'Sys::Run', |
38
|
|
|
|
|
|
|
'lazy' => 1, |
39
|
|
|
|
|
|
|
'builder' => '_init_sys', |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has '_ppid' => ( |
43
|
|
|
|
|
|
|
'is' => 'ro', |
44
|
|
|
|
|
|
|
'isa' => 'Int', |
45
|
|
|
|
|
|
|
'lazy' => 1, |
46
|
|
|
|
|
|
|
'builder' => '_init_ppid', |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _init_ppid { |
50
|
|
|
|
|
|
|
return getppid(); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub BUILD { |
54
|
|
|
|
|
|
|
my $self = shift; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# IMPORTANT: initialize our ppid! |
57
|
|
|
|
|
|
|
$self->_ppid(); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return 1; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _init_sys { |
63
|
|
|
|
|
|
|
my $self = shift; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $Sys = Sys::Run::->new( { 'logger' => $self->logger(), } ); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return $Sys; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _parent_alive { |
71
|
|
|
|
|
|
|
if(-e '/proc/'.$_[0]->_ppid()) { |
72
|
|
|
|
|
|
|
return 1; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub run { |
79
|
|
|
|
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
if ( ref($self) eq 'Job::Manager::Worker' ) { |
82
|
|
|
|
|
|
|
die('Abstract base class. Go, get your own derviate class!'); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else { |
85
|
|
|
|
|
|
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
no Moose; |
90
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=pod |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=encoding utf-8 |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 NAME |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Job::Manager::Worker - baseclass for any Worker managed by Job::Manager |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SYNOPSIS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Invoked by Job::Manager::Job. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 METHODS |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 run |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Invoked when the Job::Manager decides to run this Job. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 BUILD |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This method initialized our ppid. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 NAME |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Job::Manager::Worker - An abstract worker class. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 AUTHOR |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Dominik Schulz <dominik.schulz@gauner.org> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Dominik Schulz. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
131
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |