Bug 35479: Log start, end, and any failures for each plugin's nightly cronjob
[koha.git] / misc / cronjobs / plugins_nightly.pl
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use Try::Tiny qw( catch try );
6
7 use C4::Context;
8 use C4::Log qw( cronlogaction );
9 use Koha::Logger;
10 use Koha::Plugins;
11 use Koha::Script -cron;
12
13 my $command_line_options = join(" ",@ARGV);
14 cronlogaction({ info => $command_line_options });
15
16 my $logger = Koha::Logger->get();
17 if ( C4::Context->config("enable_plugins") ) {
18     my @plugins = Koha::Plugins->new->GetPlugins(
19         {
20             method => 'cronjob_nightly',
21         }
22     );
23
24     foreach my $plugin (@plugins) {
25         my $plugin_name = ref $plugin;
26         try {
27             cronlogaction({ info => "running nightly cronjob for plugin $plugin_name" });
28             $plugin->cronjob_nightly();
29             cronlogaction({ info => "finished nightly cronjob for plugin $plugin_name" });
30         }
31         catch {
32             cronlogaction({ info => "failed to running nightly cronjob for plugin $plugin_name with error: $_" });
33             warn "$_";
34             $logger->warn("$_");
35         };
36     }
37 }
38
39 cronlogaction({ action => 'End', info => "COMPLETED" });
40
41 =head1 NAME
42
43 plugins_nightly.pl - Run nightly tasks specified by plugins
44
45 =head1 SYNOPSIS
46
47 plugins_nightly.pl
48
49 =head1 AUTHOR
50
51 Martin Renvoize <martin.renvoize@ptfs-europe.com>
52
53 =head1 LICENSE
54
55 This file is part of Koha.
56
57 Koha is free software; you can redistribute it and/or modify it
58 under the terms of the GNU General Public License as published by
59 the Free Software Foundation; either version 3 of the License, or
60 (at your option) any later version.
61
62 Koha is distributed in the hope that it will be useful, but
63 WITHOUT ANY WARRANTY; without even the implied warranty of
64 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65 GNU General Public License for more details.
66
67 You should have received a copy of the GNU General Public License
68 along with Koha; if not, see <http://www.gnu.org/licenses>.
69
70 =cut