line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Manoc::Netwalker::Scheduler; |
2
|
|
|
|
|
|
|
#ABSTRACT netwalker task scheduler |
3
|
1
|
|
|
1
|
|
1512
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
5698
|
use namespace::autoclean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.99.2'; ##TRIAL VERSION |
7
|
|
|
|
|
|
|
with 'App::Manoc::Logger::Role'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
110
|
use Moose::Util::TypeConstraints; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
10
|
1
|
|
|
1
|
|
2175
|
use POE; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
subtype 'ManagerType' => as 'Object' => where |
13
|
|
|
|
|
|
|
sub { $_->does('App::Manoc::Netwalker::WorkersRole') }; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has config => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
isa => 'App::Manoc::Netwalker::Config', |
18
|
|
|
|
|
|
|
required => 1 |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has workers_manager => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
isa => 'ArrayRef[ManagerType]', |
25
|
|
|
|
|
|
|
default => sub { [] }, |
26
|
|
|
|
|
|
|
traits => ['Array'], |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
handles => { |
29
|
|
|
|
|
|
|
all_workers => 'elements', |
30
|
|
|
|
|
|
|
add_workers => 'push', |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has session => ( |
36
|
|
|
|
|
|
|
isa => 'POE::Session', |
37
|
|
|
|
|
|
|
is => 'ro', |
38
|
|
|
|
|
|
|
required => 1, |
39
|
|
|
|
|
|
|
lazy => 1, |
40
|
|
|
|
|
|
|
default => sub { |
41
|
|
|
|
|
|
|
POE::Session->create( object_states => [ $_[0] => [qw ( _start tick )] ] ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has tick_interval => ( |
47
|
|
|
|
|
|
|
isa => 'Int', |
48
|
|
|
|
|
|
|
is => 'ro', |
49
|
|
|
|
|
|
|
required => 1, |
50
|
|
|
|
|
|
|
default => 60, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has schema => ( |
55
|
|
|
|
|
|
|
is => 'ro', |
56
|
|
|
|
|
|
|
required => 1 |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
has next_alarm_time => ( |
61
|
|
|
|
|
|
|
is => 'rw', |
62
|
|
|
|
|
|
|
isa => 'Int', |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _start { |
66
|
|
|
|
|
|
|
my ( $self, $kernel ) = @_[ OBJECT, KERNEL ]; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$self->log->debug( "starting scheduler, tick=", $self->tick_interval ); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
foreach my $m ( @{ $self->workers_manager } ) { |
71
|
|
|
|
|
|
|
$m->on_tick($kernel); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$self->next_alarm_time( time() + 1 ); |
75
|
|
|
|
|
|
|
$kernel->alarm( tick => $self->next_alarm_time ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub tick { |
80
|
|
|
|
|
|
|
my ( $self, $kernel ) = @_[ OBJECT, KERNEL ]; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$self->log->debug("scheduler tick"); |
83
|
|
|
|
|
|
|
foreach my $m ( @{ $self->workers_manager } ) { |
84
|
|
|
|
|
|
|
$m->on_tick($kernel); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
$self->next_alarm_time( $self->next_alarm_time + $self->tick_interval ); |
87
|
|
|
|
|
|
|
$kernel->alarm( tick => $self->next_alarm_time ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub BUILD { |
91
|
|
|
|
|
|
|
shift->session(); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
no Moose; |
95
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Local Variables: |
98
|
|
|
|
|
|
|
# mode: cperl |
99
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
100
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
101
|
|
|
|
|
|
|
# cperl-indent-parens-as-block: t |
102
|
|
|
|
|
|
|
# End: |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=pod |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 NAME |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
App::Manoc::Netwalker::Scheduler |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 VERSION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
version 2.99.2 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 workers_manager |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
A list L<App::Manoc::Netwalker::WorkersRole> objects. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 session |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
The POE session used to schedule the tick |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 tick_interval |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Defaults to 1 minute. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 schema |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Manoc Schema. Required. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 next_alarm_time |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Internally used to schedule the next tick. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 METHODS |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 tick |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Call the C<on_tick> callback on all registered C<workers_manager> objects. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 AUTHORS |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=over 4 |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Gabriele Mambrini <gmambro@cpan.org> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Enrico Liguori |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Gabriele Mambrini. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
163
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |