| 1 | package ETLp::Plugin::Serial::Watch; | ||
| 2 | |||
| 3 | use MooseX::Declare; | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | ETLp::Plugin::Serial::Watch - Plugin for File Watcher | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | A file watcher is is a process that waits for the existence of a file | ||
| 12 | before calling the next job for further processing | ||
| 13 | |||
| 14 | =head1 METHODS | ||
| 15 | |||
| 16 | =head2 type | ||
| 17 | |||
| 18 | Registers the plugin type. | ||
| 19 | |||
| 20 | =head2 run | ||
| 21 | |||
| 22 | Executes the supplied perl code. | ||
| 23 | |||
| 24 | =head3 parameters | ||
| 25 | |||
| 26 | * none | ||
| 27 | |||
| 28 | =head3 returns | ||
| 29 | |||
| 30 | * void | ||
| 31 | |||
| 32 | =head1 ITEM | ||
| 33 | |||
| 34 | The item attribute hashref contains specific configuration information | ||
| 35 | for ETLp::Plugin::Serial::OS | ||
| 36 | |||
| 37 | =head2 command | ||
| 38 | |||
| 39 | The operating system command being run | ||
| 40 | |||
| 41 | =head2 timeout | ||
| 42 | |||
| 43 | This is an optional parameter that specifies when the command execution | ||
| 44 | should abort (in seconds). | ||
| 45 | |||
| 46 | =cut | ||
| 47 | |||
| 48 | class ETLp::Plugin::Serial::Watch extends ETLp::Plugin { | ||
| 49 | use ETLp::File::Watch; | ||
| 50 | use Data::Dumper; | ||
| 51 | |||
| 52 | sub type { | ||
| 53 | return 'watch'; | ||
| 54 | } | ||
| 55 | |||
| 56 | method run { | ||
| 57 | my $item = $self->item; | ||
| 58 | my $directory = $self->config->{config}->{directory} || | ||
| 59 | ETLpException->throw("Directory not defined"); | ||
| 60 | |||
| 61 | $self->logger->debug("Directory: $directory"); | ||
| 62 | |||
| 63 | my $fw = ETLp::File::Watch->new( | ||
| 64 | directory => $directory, | ||
| 65 | file_pattern => $item->{file_pattern}, | ||
| 66 | call => $self->config->{config}->{call}, | ||
| 67 | wait_time => $item->{wait_time} || 1, | ||
| 68 | duration => $item->{duration}, | ||
| 69 | raise_no_file_error => $item->{no_file_error} || 0, | ||
| 70 | exit_on_detection => $item->{exit_on_detection}|| 0, | ||
| 71 | ); | ||
| 72 | |||
| 73 | my $res = $fw->watch; | ||
| 74 | |||
| 75 | if ($res == 1) { | ||
| 76 | $self->audit->item->update_message('File(s) detected'); | ||
| 77 | } else { | ||
| 78 | $self->audit->item->update_message('No file(s) detected'); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | } | ||
| 83 | |||
| 84 |