aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/send-failure-summary (renamed from bin/send-reports-failure-summary)11
-rw-r--r--conf/crontab-example2
-rwxr-xr-xperllib/Open311/PostServiceRequestUpdates.pm22
-rw-r--r--t/open311/post-service-request-updates.t4
4 files changed, 34 insertions, 5 deletions
diff --git a/bin/send-reports-failure-summary b/bin/send-failure-summary
index c7a5b4086..1a435dc7c 100755
--- a/bin/send-reports-failure-summary
+++ b/bin/send-failure-summary
@@ -1,9 +1,8 @@
#!/usr/bin/env perl
-# send-reports-failure-summary:
-# Prints a summary of report sending failures
+# send-failure-summary:
+# Prints a summary of report/update sending failures
-use strict;
use warnings;
use v5.14;
@@ -15,6 +14,12 @@ BEGIN {
}
use FixMyStreet::Script::Reports;
+use Open311::PostServiceRequestUpdates;
+# report summary
my $manager = FixMyStreet::Script::Reports->new;
$manager->end_summary_failures;
+
+# updates summary
+my $updates = Open311::PostServiceRequestUpdates->new;
+$updates->summary_failures;
diff --git a/conf/crontab-example b/conf/crontab-example
index 86fcee80c..568b07e2e 100644
--- a/conf/crontab-example
+++ b/conf/crontab-example
@@ -12,7 +12,7 @@ PATH=/usr/local/bin:/usr/bin:/bin
# send-reports has three rows so that its 8am entry can be run with --verbose to send a morning summary of anything that's gone wrong
*/5 * * * * "$FMS/commonlib/bin/run-with-lockfile.sh" -n "$LOCK_DIR/send-reports.lock" "$FMS/bin/send-reports" || echo "stalled?"
-0 8 * * * "$FMS/bin/send-reports-failure-summary"
+0 8 * * * "$FMS/bin/send-failure-summary"
2 * * * * "$FMS/commonlib/bin/run-with-lockfile.sh" -n "$LOCK_DIR/send-alerts.lock" "$FMS/bin/send-alerts" || echo "stalled?"
22,52 * * * * "$FMS/commonlib/bin/run-with-lockfile.sh" -n "$LOCK_DIR/send-questionnaires.lock" "$FMS/bin/send-questionnaires" || echo "stalled?"
diff --git a/perllib/Open311/PostServiceRequestUpdates.pm b/perllib/Open311/PostServiceRequestUpdates.pm
index fadd063da..68823343c 100755
--- a/perllib/Open311/PostServiceRequestUpdates.pm
+++ b/perllib/Open311/PostServiceRequestUpdates.pm
@@ -141,6 +141,28 @@ sub process_update {
}
}
+sub summary_failures {
+ my $self = shift;
+ my $bodies = $self->fetch_bodies;
+ my $params = $self->construct_query(1);
+ my $u = FixMyStreet::DB->resultset("Comment")
+ ->to_body([ keys %$bodies ])
+ ->search({ "me.send_fail_count" => { '>', 0 } })
+ ->search($params, { join => "problem" });
+
+ my $base_url = FixMyStreet->config('BASE_URL');
+ my $sending_errors;
+ while (my $row = $u->next) {
+ my $url = $base_url . "/report/" . $row->problem_id;
+ $sending_errors .= "\n" . '=' x 80 . "\n\n" . "* $url, update " . $row->id . " failed "
+ . $row->send_fail_count . " times, last at " . $row->send_fail_timestamp
+ . ", reason " . $row->send_fail_reason . "\n";
+ }
+ if ($sending_errors) {
+ print '=' x 80 . "\n\n" . "The following updates failed sending:\n$sending_errors";
+ }
+}
+
sub log {
my ($self, $comment, $msg) = @_;
return unless $self->verbose;
diff --git a/t/open311/post-service-request-updates.t b/t/open311/post-service-request-updates.t
index adfd4e3c5..71bba4af7 100644
--- a/t/open311/post-service-request-updates.t
+++ b/t/open311/post-service-request-updates.t
@@ -1,12 +1,13 @@
#!/usr/bin/env perl
use FixMyStreet::TestMech;
+use Test::Output;
my $mech = FixMyStreet::TestMech->new;
use_ok( 'Open311::PostServiceRequestUpdates' );
-my $o = Open311::PostServiceRequestUpdates->new( site => 'fixmystreet.com' );
+my $o = Open311::PostServiceRequestUpdates->new;
my $params = {
send_method => 'Open311',
@@ -130,6 +131,7 @@ subtest 'Oxfordshire gets an ID' => sub {
$o->send;
$c2->discard_changes;
is $c2->send_fail_count, 1, 'Oxfordshire update tried to send, failed';
+ stdout_like { $o->summary_failures } qr/The following updates failed sending/;
};
};