Pluggable/EventHandler.pm

filter: Statementstmt 23.5% 16 / 68 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 22.2% 4 / 18 Podpod 100% 12 / 12 totaltotal 30.4% 32 / 105 CC 5 SCAR 15.1
CC
5
Cov
22%
sig_child
12.0
sig_INT
12.0
__ANON__
2.0
CRAP 4.5
« Pluggable/Plugin/DefaultEventHandler.pm ↑ Summary Pluggable.pm »
1 package Schedule::Pluggable::EventHandler;
2  
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 #use IO::Prompt;
6 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use POSIX qw/ strftime /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 $Data::Dumper::Sortkeys = 1;
9 has EventsPlugins => ( is => 'rw',
10 isa => 'ArrayRef',
11 reader => '_get_EventsPlugins',
12 0 ▶ default => sub { return [ qw/DefaultEventHandler/ ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
13 1 );
14  
15 before BUILD => sub {
16 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 0 $self->load_plugins( @{ $self->_get_EventsPlugins } );
18 1 };
19  
20 sub worker_manager_start {
21 0 ▶ my $self = shift;
Subroutine worker_manager_start: not called CC=1 SCAR=6.9
Pod documented
22 0 $self->event_handler(Event => 'ManagerStart');
23 }
24 sub worker_manager_stop {
25 0 ▶ my $self = shift;
Subroutine worker_manager_stop: not called CC=1 SCAR=6.9
Pod documented
26 0 $self->event_handler(Event => 'ManagerStop');
27 }
28 # Called with the return value when a job ends
29 sub sig_child {
30 0 ▶ my $self = shift;
Subroutine sig_child: not called CC=3 SCAR=24.8
Pod documented
31 0 my ( $id, $return_value ) = @_;
32 0 my $status = $self->_get_status();
33 0 my $job_name = $status->{Ids}{$id};
34 0 my $command = $status->{Jobs}{$job_name}{command};
35 0 ▶ if ($return_value == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($return_value == 0) { } 0 0 0
36 $self->event_handler(Event => 'JobSucceeded',
37 JobName => $job_name,
38 Command => $command,
39 Stderr => $status->{Jobs}{ $job_name }{stderr},
40 Stdout => $status->{Jobs}{ $job_name }{stdout},
41 0 );
42 }
43 else {
44 0 ▶ $status->{Jobs}{$job_name}{stderr} ||= [ pop(@{ $status->{Jobs}{$job_name}{stdout} }) ];
Condition0%0/2
$status->{"Jobs"}{$job_name}{"stderr"} ||= [pop @{$$status{"Jobs"}{$job_name}{"stdout"};}]
l!l
00
MC/DC0%0/1
$status->{"Jobs"}{$job_name}{"stderr"} ||= [pop @{$$status{"Jobs"}{$job_name}{"stdout"};}]
$status->{"Jobs"}{$job_name}{"stderr"}
Truth table0%0/2
A
A= $status->{"Jobs"}{$job_name}{"stderr"}
Aresult
11
00
45 $self->event_handler( Event => 'JobFailed',
46 JobName => $job_name,
47 Command => $command,
48 ReturnValue => $return_value,
49 Stderr => $status->{Jobs}{ $job_name }{stderr},
50 Stdout => $status->{Jobs}{ $job_name }{stdout},
51 0 );
52 }
53 0 $self->_update_status({ name => $job_name }, { status => $return_value, } );
54 }
55 sub max_workers_reached {
56 0 ▶ my $self = shift;
Subroutine max_workers_reached: not called CC=1 SCAR=6.9
Pod documented
57 0 $self->event_handler( Event => 'MaxJobsReached');
58 }
59 sub worker_stdout {
60 0 ▶ my $self = shift;
Subroutine worker_stdout: not called CC=1 SCAR=6.9
Pod documented
61 0 my ( $stdout, $job ) = @_;
62 0 $self->_update_status({ id => $job->ID }, { stdout => [ $stdout ] });
63 $self->event_handler(Event => 'JobStdout',
64 JobName => $job->{name},
65 Command => $job->{command},
66 0 Stdout => $stdout,
67 );
68 }
69 sub worker_stderr {
70 0 ▶ my $self = shift;
Subroutine worker_stderr: not called CC=1 SCAR=6.9
Pod documented
71 0 my ( $stderr, $job ) = @_;
72 0 $stderr =~ s! at\s+\S+POE/Wheel/Run.pm\s+line\s+\d+.!!;
73  
74 0 $self->_update_status({ id => $job->ID }, { stderr => [ $stderr ] });
75 $self->event_handler(Event => 'JobStderr',
76 JobName => $job->{name},
77 Command => $job->{command},
78 0 Stderr => $stderr,
79 );
80 }
81 sub worker_done {
82 0 ▶ my $self = shift;
Subroutine worker_done: not called CC=1 SCAR=6.9
Pod documented
83 0 my ( $job ) = @_;
84  
85 0 $self->_update_status({ id => $job->ID }, { timefinished => strftime("%d/%m/%Y %H:%M:%S", localtime(time)) });
86 0 $self->event_handler(Event => 'JobDone',
87 JobName => $job->name,
88 Command => $job->command,
89 ) ;
90 }
91 sub worker_started {
92 0 ▶ my $self = shift;
Subroutine worker_started: not called CC=1 SCAR=6.9
Pod documented
93  
94 0 my ( $job ) = @_;
95  
96 0 $self->_update_status({ name => $job->name }, { Id => $job->ID, Pid => $job->PID, timestarted => strftime("%d/%m/%Y %H:%M:%S", localtime(time)) });
97 $self->event_handler(Event => 'JobStarted',
98 JobName => $job->{name},
99 Command => $job->{command},
100 0 );
101  
102 }
103 sub sig_INT {
104 0 ▶ my $self = shift;
Subroutine sig_INT: not called CC=3 SCAR=24.8
Pod documented
105 0 print "Sig INT!\n";
106 0 my $status = $self->_get_status();
107 0 my $running = $self->has_workers;
108 0 ▶ if ($running > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($running > 1) 0 0 0
109 0 foreach my $j (keys %{ $status->{Running} }) {
110 0 my %job = %{ $status->{Jobs}{$j} };
111 0 print join(" ", @job{ qw/Id Pid name command timestarted/} ), "\n";
112 }
113 }
114 0 exit(0);
115 }
116 sub sig_BUS {
117 0 ▶ confess("sig_BUS\n".Data::Dumper->Dump([\@_],[qw/@_/]));
Subroutine sig_BUS: not called CC=1 SCAR=6.9
Pod documented
118 }
119 sub sig_SEGV {
120 0 ▶ confess("sig_SEGV\n".Data::Dumper->Dump([\@_],[qw/@_/]));
Subroutine sig_SEGV: not called CC=1 SCAR=6.9
Pod documented
121 }
122 sub event_handler {
123 0 ▶ my $self = shift;
Subroutine event_handler: not called CC=1 SCAR=6.9
Pod documented
124 }
125 1 1;
126 __END__
127  
128 =head1 NAME
129  
130 Schedule::Pluggable::EventHandler - Moose Role to handle the interface to MooseX::Workers by providing the methods which get called
131  
132 =head1 DESCRIPTION
133  
134 Moose Role to handle the interface to MooseX::Workers by providing the methods which get called when events occur - not runnable on it's own
135  
136 =head1 METHODS - none of which are for public use
137  
138 =over
139  
140 =item worker_manager_start - called when the worker manager starts up
141  
142 =item worker_manager_stop - called when the worker manager shuts down
143  
144 =item max_workers_reached - called when a job is queued when the number of jobs already running is equal to the maximum specified
145  
146 =item sig_child - called when a job ends supplying the return code
147  
148 =item worker_stdout - called whenever a job sends some output to standard output
149  
150 =item worker_stderr - called whenever a job sends some output to standard error
151  
152 =item worker_started - called when a job starts up
153  
154 =item worker_done - called when a job finishes
155  
156 =item sig_INT - called when the interupt signal (control-c) is recieved
157  
158 =item event_handler - A stub method designed for Event Handler Plugins to process after
159  
160 =item sig_BUS - called when a Bus error signal is recieved - causes schedule to abort
161  
162 =item sig_SEGV - called when a segmentation violation signal is received - causes schedule to abort
163  
164 =back
165  
166 =cut
167  
« Pluggable/Plugin/DefaultEventHandler.pm ↑ Summary Pluggable.pm »