| 1 | |||||||||||||||||||||||||||||
| 2 | package Schedule::Pluggable::Plugin::DefaultEventHandler; | ||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use FileHandle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use POSIX qw/ strftime /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | has EventsToReport => ( is => 'rw', | |||||||||||||||||||||||||||
| 8 | isa => 'Str', | ||||||||||||||||||||||||||||
| 9 | required => 1, | ||||||||||||||||||||||||||||
| 10 | default => qq/JobStarted,JobFailed,JobSucceeded,JobStderr/, | ||||||||||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||||||||||
| 12 | 1 | has ShowTimeStamp => ( is => 'rw', | |||||||||||||||||||||||||||
| 13 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 14 | required => 1, | ||||||||||||||||||||||||||||
| 15 | default => 1 ); | ||||||||||||||||||||||||||||
| 16 | has MessagesTo => ( is => 'rw', | ||||||||||||||||||||||||||||
| 17 | isa => 'Any', | ||||||||||||||||||||||||||||
| 18 | required => 1, | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | default => sub { FileHandle->new('>&1') }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 20 | 1 | ); | |||||||||||||||||||||||||||
| 21 | has ErrorsTo => ( is => 'rw', | ||||||||||||||||||||||||||||
| 22 | isa => 'Any', | ||||||||||||||||||||||||||||
| 23 | required => 1, | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | default => sub { FileHandle->new('>&1') }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 25 | 1 | ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | after event_handler => sub { | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||
| 30 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 31 | 0 | ▶ | return if exists $params{JobName} and $params{JobName} =~ m/^MonitorJobs$/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $params{"JobName"} and $params{"JobName"} =~ /^MonitorJobs$/i
MC/DC0%0/2
exists $params{"JobName"} and $params{"JobName"} =~ /^MonitorJobs$/i
exists $params{"JobName"}
$params{"JobName"} =~ /^MonitorJobs$/i
Truth table0%0/3
A and B
A= exists $params{"JobName"}B= $params{"JobName"} =~ /^MonitorJobs$/i
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | return if $self->EventsToReport =~ m/^none$/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | my $event = $params{Event}; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | return if $self->EventsToReport !~ m!^all$!i and | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->EventsToReport =~ /^all$/i or $self->EventsToReport =~ /\b$event\b/
MC/DC0%0/2
$self->EventsToReport =~ /^all$/i or $self->EventsToReport =~ /\b$event\b/
$self->EventsToReport =~ /^all$/i
$self->EventsToReport =~ /\b$event\b/
Truth table0%0/3
A or B
A= $self->EventsToReport =~ /^all$/iB= $self->EventsToReport =~ /\b$event\b/
| |||||||||||||||||||||||||||||
| 35 | $self->EventsToReport !~ m!\b$event\b!; | ||||||||||||||||||||||||||||
| 36 | 0 | my %whattoreport = ( | |||||||||||||||||||||||||||
| 37 | JobQueued => [qw/ Event JobName Command /], | ||||||||||||||||||||||||||||
| 38 | JobStarted => [qw/ Event JobName Command /], | ||||||||||||||||||||||||||||
| 39 | JobDone => [qw/ Event JobName Command /], | ||||||||||||||||||||||||||||
| 40 | JobStderr => [qw/ Event JobName Stderr /], | ||||||||||||||||||||||||||||
| 41 | JobStdout => [qw/ Event JobName Stdout /], | ||||||||||||||||||||||||||||
| 42 | JobFailed => [qw/ Event JobName Command ReturnValue Stderr /], | ||||||||||||||||||||||||||||
| 43 | JobSucceeded => [qw/ Event JobName Command /], | ||||||||||||||||||||||||||||
| 44 | MaxJobsReached => [qw/ Event /], | ||||||||||||||||||||||||||||
| 45 | ManagerStart => [qw/ Event /], | ||||||||||||||||||||||||||||
| 46 | ManagerStart => [qw/ Event /], | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return unless exists $whattoreport{ $params{Event} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | my @mess = (); | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | push(@mess, strftime('%d/%m/%Y %H:%M:%S', localtime(time()))) if $self->ShowTimeStamp; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | foreach my $field (@{ $whattoreport{$params{Event}} }) { | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | push(@mess, ref($params{$field}) eq 'ARRAY' ? @{ $params{$field} } : $params{$field}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | my $handle = $params{Event} =~ m/(JobStderr|JobFailed)/ ? $self->ErrorsTo | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | : $self->MessagesTo; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if (ref($handle) eq 'FileHandle') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | $handle->print(join(' ',@mess)."\n"); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||
| 61 | 0 | $handle->(join(' ',@mess)."\n"); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 1 | }; | |||||||||||||||||||||||||||
| 64 | 1 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 1 | 1; | |||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head1 NAME | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | Schedule::Pluggable::Plugin::DefaultEventHandler - Plugin Role for Schedule::Pluggable to handle events | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Plugin to provide default handling of events in a schedule. | ||||||||||||||||||||||||||||
| 75 | Basically, it just prints out the details of the events specified in the array EventsToReport with an optional preceding date/time stamp | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head1 METHODS | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =over | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =item event_handler | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | The method required by all event handler plugins - gets called but the methods in Schedule::Pluggable::Monitor when they are called | ||||||||||||||||||||||||||||
| 84 | when events occur | ||||||||||||||||||||||||||||
| 85 | Is supplied a handle to the Schedule::Pluggable object and a hash specifying what has happened | ||||||||||||||||||||||||||||
| 86 | the following table shows what gets passed depending on the event :- | ||||||||||||||||||||||||||||
| 87 | B<Event> B<Parameters passed> | ||||||||||||||||||||||||||||
| 88 | JobQueued => Event JobName Command | ||||||||||||||||||||||||||||
| 89 | JobStarted => Event JobName Command | ||||||||||||||||||||||||||||
| 90 | JobDone => Event JobName Command | ||||||||||||||||||||||||||||
| 91 | JobStderr => Event JobName Stderr | ||||||||||||||||||||||||||||
| 92 | JobStdout => Event JobName Stdout | ||||||||||||||||||||||||||||
| 93 | JobFailed => Event JobName Command ReturnValue Stderr | ||||||||||||||||||||||||||||
| 94 | JobSucceeded => Event JobName Command | ||||||||||||||||||||||||||||
| 95 | MaxJobsReached => Event | ||||||||||||||||||||||||||||
| 96 | ManagerStart => Event | ||||||||||||||||||||||||||||
| 97 | ManagerStart => Event | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =back | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | e.g. | ||||||||||||||||||||||||||||
| 102 | C<$self->event_handler(Event => 'JobStderr', | ||||||||||||||||||||||||||||
| 103 | JobName => $job->{name}, | ||||||||||||||||||||||||||||
| 104 | Command => $job->{command}, | ||||||||||||||||||||||||||||
| 105 | Stderr => $stderr, | ||||||||||||||||||||||||||||
| 106 | );> | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||||||||||