From: Jason Boyer Date: Fri, 28 Aug 2020 21:13:14 +0000 (-0400) Subject: LP1893463: Prevent duplicated report outputs X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=7ae38e79721e71786f81c9c1d0a7ac1436cfa8fb;p=evergreen%2Fpines.git LP1893463: Prevent duplicated report outputs When re-running recurring reports that are interrupted, it's possible to end up with a duplicate copy of the next recurrance of that report. This branch adds a unique index to reporter.schedule and tells clark-kent.pl not to worry about it. For the purposes of this change a duplicate report is one where report.schedule has identical values for report, (output) folder, runner, run_time, and email. Signed-off-by: Jason Boyer Signed-off-by: Chris Sharp --- diff --git a/Open-ILS/src/reporter/clark-kent.pl b/Open-ILS/src/reporter/clark-kent.pl index 320ee8c5c9..9db6778f42 100755 --- a/Open-ILS/src/reporter/clark-kent.pl +++ b/Open-ILS/src/reporter/clark-kent.pl @@ -250,7 +250,7 @@ for my $r ( @reports ) { WHERE id = ?; SQL - $logger->debug('Report SQL: ' . $r->{resultset}->toSQL); + $logger->debug('Report SQL: ' . $r->{resultset}->toSQL); $sth = $data_dbh->prepare($r->{resultset}->toSQL); $sth->execute; @@ -314,7 +314,9 @@ for my $r ( @reports ) { VALUES ( ?, ?, ?, ?::TIMESTAMPTZ + ?, ?, ?, ?, ?, ?, ?, ? ); SQL - $state_dbh->do( + my $prevP = $state_dbh->{PrintError}; + $state_dbh->{PrintError} = 0; + if (!$state_dbh->do( $sql, {}, $r->{report}->{id}, @@ -329,7 +331,11 @@ for my $r ( @reports ) { $r->{chart_pie}, $r->{chart_bar}, $r->{chart_line}, - ); + )) { + # Ignore duplicate key errors on reporter.schedule (err 7 is a fatal query error). Just look for the constraint name in the message to avoid l10n issues. + warn($state_dbh->errstr()) unless $state_dbh->err() == 7 && $state_dbh->errstr() =~ m/rpt_sched_recurrence_once_idx/; + } + $state_dbh->{PrintError} = $prevP; } $state_dbh->do(<<' SQL',{}, $r->{id}); diff --git a/Open-ILS/src/sql/Pg/reporter-schema.sql b/Open-ILS/src/sql/Pg/reporter-schema.sql index 4ed00474cd..eb07999c53 100644 --- a/Open-ILS/src/sql/Pg/reporter-schema.sql +++ b/Open-ILS/src/sql/Pg/reporter-schema.sql @@ -110,6 +110,7 @@ CREATE TABLE reporter.schedule ( ); CREATE INDEX rpt_sched_runner_idx ON reporter.schedule (runner); CREATE INDEX rpt_sched_folder_idx ON reporter.schedule (folder); +CREATE UNIQUE INDEX rpt_sched_recurrence_once_idx ON reporter.schedule (report,folder,runner,run_time,email); CREATE OR REPLACE VIEW reporter.simple_record AS SELECT r.id, diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reporter_schedule_uniqueness.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reporter_schedule_uniqueness.sql new file mode 100644 index 0000000000..1a2b22fa44 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reporter_schedule_uniqueness.sql @@ -0,0 +1,9 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +-- Explicitly supply the name because it is referenced in clark-kent.pl +CREATE UNIQUE INDEX rpt_sched_recurrence_once_idx ON reporter.schedule (report,folder,runner,run_time,email); + +COMMIT; +