App-RunCron

 view release on metacpan or  search on metacpan

lib/App/RunCron.pm  view on Meta::CPAN


__END__

=for stopwords cron crontab logfile eg

=encoding utf-8

=head1 NAME

App::RunCron - making wrapper script for crontab

=head1 SYNOPSIS

    use App::RunCron;
    my $runner = App::RunCron->new(
        timestamp => 1,
        command   => [@ARGV],
        logfile   => 'tmp/log%Y-%m-%d.log',
        reporter  => 'Stdout',
        error_reporter => [
            'Stdout',
            'File', {
                file => 'tmp/error%Y-%m-%d.log'
            },
        ],
    );
    $runner->run;

=head1 DESCRIPTION

App::RunCron is a software for making wrapper script for running cron tasks.

App::RunCron can separate reporting way if the command execution success or failed
(i.e. fails to start, or returns a non-zero exit code, or killed by a signal).
It is handled by `reporter` and `error_reporter` option.

By default, `reporter` is 'None' and `error_reporter` is 'Stdout'.
It prints the outputs the command if and only if the command execution failed.
In other words, this behaviour causes L<cron(8)> to send mail when and only when an error occurs.

Default behaviour is same like L<cronlog|https://github.com/kazuho/kaztools/blob/master/cronlog>.

=head1 OPTIONS

=head2 timestamp

Add timestamp or not. (Default: undef)

=head2 tag

Identifier of the job name. (Optional)

=head2 command

command to be executed. (Required)

=head2 logfile

If logfile is specified, stdout and stderr of the command will be logged to the file so that it could be used for later inspection. 
If not specified, the outputs will not be logged.
The logfile can be a C<strftime> format. eg. '%Y-%m-%d.log'. (NOTICE: '%' must be escaped in crontab.)

=head2 reporter|error_reporter|common_reporter

C<common_reporter> is optional, processing after C<(error_)?reporter> is handled.

The C<reporter>, C<error_reporter> and C<common_reporter> can be like following.

=over

=item C<< $module_name >>

=item C<< [$module_name[, \%opt], ...] >>

=item C<< $coderef >>

=back

I<$module_name> package name of the plugin. You can write it as two form like L<Plack::Middleware>:

    reporter => 'Stdout',    # => loads App::RunCron::Reporter::Stdout

If you want to load a plugin in your own name space, use the '+' character before a package name, like following:

    reporter => '+MyApp::Reporter::Foo', # => loads MyApp::Reporter::Foo

=head2 announcer

Package name of an "Announcer" which announce job information before running the job. (Optional)

=head2 METHODS AND ACCESORS

=head3 C<< $self->run >>

Running the job.

=head3 C<< my $str = $self->result_line >>

One line result string of the command.

=head3 C<< my $str = $self->report >>

Retrieve the output of the command.

=head3 C<< my $bool = $self->is_success >>

command is success or not.

=head3 C<< my $int = $self->exit_code >>

same as C<$?>

=head3 C<< my $int = $self->child_exit_code >>

exit code of child process.

=head3 C<< my $int = $self->child_signal >>

signal number if chile process accepted a signal.

=head1 SEE ALSO



( run in 2.633 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )