<success_template>LOCALSTATEDIR/data/report-success</success_template>
<fail_template>LOCALSTATEDIR/data/report-fail</fail_template>
</files>
+ <!-- Number of reports that can be processed simultaneously. This
+ value can overriden by the -c/-concurrency command-line switch
+ of clark-kent.pl.
+ -->
+ <parallel>1</parallel>
+ <!-- Maximum number of rows in the query results allowed before
+ Clark will refuse to draw a pie, bar, or line chart. This
+ value can be overriden by the -max-rows-for-charts command-line
+ switch of clark-kent.pl.
+ -->
+ <max_rows_for_charts>1000</max_rows_for_charts>
+ <!-- Maximum amount of time (in minutes) that an SQL query initiated
+ by Clark Kent will be allowed to run before it is terminated.
+ This value can be overriden by the -statement-timeout
+ command-line switch of clark-kent.pl.
+ -->
+ <statement_timeout>60</statement_timeout>
+ <!-- Maximum number of results permitted. If set to a numeric value,
+ Clark will limit the number of rows returned by report queries
+ to this value. Note that it will not be apparent to a user
+ running a report from the staff interface that their report
+ has been limited in this fashion. This setting can be
+ overriden by the -resultset-limit command-line switch of
+ clark-kent.pl.
+ -->
+ <resultset_limit></resultset_limit>
</setup>
</reporter>
use open ':utf8';
-my ($count, $config, $sleep_interval, $lockfile, $daemon) = (1, 'SYSCONFDIR/opensrf_core.xml', 10, '/tmp/reporter-LOCK');
+my ($config, $sleep_interval, $lockfile, $daemon) = ('SYSCONFDIR/opensrf_core.xml', 10, '/tmp/reporter-LOCK');
+
+my $opt_count;
+my $opt_max_rows_for_charts;
+my $opt_statement_timeout;
+my $opt_resultset_limit;
GetOptions(
"daemon" => \$daemon,
"sleep=i" => \$sleep_interval,
- "concurrency=i" => \$count,
+ "concurrency=i" => \$opt_count,
+ "max-rows-for-charts=i" => \$opt_max_rows_for_charts,
+ "resultset-limit=i" => \$opt_resultset_limit,
+ "statement-timeout=i" => \$opt_statement_timeout,
"bootstrap|boostrap=s" => \$config,
"lockfile=s" => \$lockfile,
);
my $state_dsn = "dbi:" . $state_db{db_driver} . ":dbname=" . $state_db{db_name} .';host=' . $state_db{db_host} . ';port=' . $state_db{db_port};
my $data_dsn = "dbi:" . $data_db{db_driver} . ":dbname=" . $data_db{db_name} .';host=' . $data_db{db_host} . ';port=' . $data_db{db_port};
+my $count = $opt_count //
+ $sc->config_value( reporter => setup => 'parallel' ) //
+ 1;
+$count = 1 unless $count =~ /^\d+$/ && $count > 0;
+my $statement_timeout = $opt_statement_timeout //
+ $sc->config_value( reporter => setup => 'statement_timeout' ) //
+ 60;
+$statement_timeout = 60 unless $statement_timeout =~ /^\d+$/;
+my $max_rows_for_charts = $opt_max_rows_for_charts //
+ $sc->config_value( reporter => setup => 'max_rows_for_charts' ) //
+ 1000;
+$max_rows_for_charts = 1000 unless $max_rows_for_charts =~ /^\d+$/;
+my $resultset_limit = $opt_resultset_limit //
+ $sc->config_value( reporter => setup => 'resultset_limit' );
+
my ($dbh,$running,$sth,@reports,$run, $current_time);
if ($daemon) {
$r->{resultset}->set_pivot_label($report_data->{__pivot_label}) if $report_data->{__pivot_label};
$r->{resultset}->set_pivot_default($report_data->{__pivot_default}) if $report_data->{__pivot_default};
$r->{resultset}->relative_time($r->{run_time});
+ $r->{resultset}->resultset_limit($resultset_limit) if $resultset_limit;
push @reports, $r;
}
RaiseError => 1
}
);
+ $data_dbh->do('SET statement_timeout = ?', {}, ($statement_timeout * 60 * 1000));
try {
$state_dbh->do(<<' SQL',{}, $r->{id});
# Time for a pie chart
if ($r->{chart_pie}) {
- my $pics = draw_pie($r, $file);
- for my $pic (@$pics) {
- print $index "<img src='report-data.html.$pic->{file}' alt='$pic->{name}'/>$br4";
+ if (scalar(@{$r->{data}}) > $max_rows_for_charts) {
+ print $index "<strong>Report output has too many rows to make a pie chart</strong>$br4";
+ } else {
+ my $pics = draw_pie($r, $file);
+ for my $pic (@$pics) {
+ print $index "<img src='report-data.html.$pic->{file}' alt='$pic->{name}'/>$br4";
+ }
}
}
print $index $br4;
# Time for a bar chart
if ($r->{chart_bar}) {
- my $pics = draw_bars($r, $file);
- for my $pic (@$pics) {
- print $index "<img src='report-data.html.$pic->{file}' alt='$pic->{name}'/>$br4";
+ if (scalar(@{$r->{data}}) > $max_rows_for_charts) {
+ print $index "<strong>Report output has too many rows to make a bar chart</strong>$br4";
+ } else {
+ my $pics = draw_bars($r, $file);
+ for my $pic (@$pics) {
+ print $index "<img src='report-data.html.$pic->{file}' alt='$pic->{name}'/>$br4";
+ }
}
}
print $index $br4;
# Time for a bar chart
if ($r->{chart_line}) {
- my $pics = draw_lines($r, $file);
- for my $pic (@$pics) {
- print $index "<img src='report-data.html.$pic->{file}' alt='$pic->{name}'/>$br4";
- }
+ if (scalar(@{$r->{data}}) > $max_rows_for_charts) {
+ print $index "<strong>Report output has too many rows to make a line chart</strong>$br4";
+ } else {
+ my $pics = draw_lines($r, $file);
+ for my $pic (@$pics) {
+ print $index "<img src='report-data.html.$pic->{file}' alt='$pic->{name}'/>$br4";
+ }
+ }
}
# and that's it!