-
-
Notifications
You must be signed in to change notification settings - Fork 290
/
Copy pathRunReports.pl
executable file
·82 lines (65 loc) · 2.13 KB
/
RunReports.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env perl
use strict;
use warnings;
use English;
use FindBin;
use lib "$FindBin::Bin/../lib";
use List::AllUtils qw ( any );
use MusicBrainz::Server::Context;
use MusicBrainz::Server::Log qw( log_info log_debug );
use MusicBrainz::Server::ReportFactory;
use POSIX qw( SIGALRM );
$OUTPUT_AUTOFLUSH = 1;
@ARGV = '^' if not @ARGV;
my $c = MusicBrainz::Server::Context->create_script_context();
my $errors = 0;
for my $name (MusicBrainz::Server::ReportFactory->all_report_names) {
unless (any { $name =~ /$_/i } @ARGV) {
log_debug { "Not running $name" };
next;
}
my $report = MusicBrainz::Server::ReportFactory->create_report($name, $c);
log_info { "Running $name" };
my $t0 = time;
my $ONE_HOUR = 1 * 60 * 60;
my $exit_code = eval {
my $child = fork();
if ($child == 0) {
alarm($ONE_HOUR);
my $action = POSIX::SigAction->new(sub {
exit(42);
});
$action->safe(1);
POSIX::sigaction(SIGALRM, $action);
Sql::run_in_transaction(sub {
$report->run;
$c->sql->do('DELETE FROM report.index WHERE report_name = ?', $report->table);
$c->sql->insert_row('report.index', { report_name => $report->table })
}, $c->sql);
alarm(0);
exit(0);
}
waitpid($child, 0);
if (($CHILD_ERROR >> 8) == 42) {
die 'Report took over 1 hour to run';
}
};
if ($EVAL_ERROR) {
warn "$name died with $EVAL_ERROR\n";
++$errors;
next;
}
my $t = time() - $t0;
log_info { "$name finished; time=$t" };
}
log_info { 'Completed with 1 error' } if $errors == 1;
log_info { "Completed with $errors errors" } if $errors != 1;
exit($errors ? 1 : 0);
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2012 MetaBrainz Foundation
Copyright (C) 2009 Lukas Lalinsky
Copyright (C) 1998 Robert Kaye
This file is part of MusicBrainz, the open internet music database,
and is licensed under the GPL version 2, or (at your option) any
later version: http://www.gnu.org/licenses/gpl-2.0.txt
=cut