Skip to content

Commit

Permalink
fixup! add reports failed count to sendreports output
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Feb 15, 2021
1 parent 84522b1 commit 5c40ee1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions perllib/FixMyStreet/Script/Reports.pm
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,21 @@ sub end_summary_failures {
{
order_by => { -desc => 'confirmed' }
});
my @ids;
my ( @ids, %bodies );
while (my $row = $unsent->next) {
my $base_url = FixMyStreet->config('BASE_URL');
push @ids, $row->id;
my $key = join ', ', @{ $row->body_names };
$bodies{$key} ||= [];
push @{ $bodies{$key} }, $row->id;
$sending_errors .= "\n" . '=' x 80 . "\n\n" . "* " . $base_url . "/report/" . $row->id . ", failed "
. $row->send_fail_count . " times, last at " . $row->send_fail_timestamp
. ", reason " . $row->send_fail_reason . "\n";
}
if ($sending_errors) {
my $count = $unsent->count;
my $list = join ', ', @ids;
my $bodies = join '\n', map { "$_ (" . scalar @{ $bodies{$_} } . "): " . join ', ', @{ $bodies{$_} } } keys %bodies;

print "The following $count reports had problems sending:\n$list\n$sending_errors";
print "The following $count reports had problems sending:\n$bodies\n$sending_errors";
}
}

Expand Down
2 changes: 1 addition & 1 deletion t/sendreport/failures.t
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $p1->update({
subtest "check sendreport failure messages" => sub {
my $e = FixMyStreet::Script::Reports->new;
my ($id1, $id2) = ( $p1->id, $p2->id );
stdout_like { $e->end_summary_failures } qr%The following 2 reports had problems sending:\n$id2, $id1.*report/$id2.*report/$id1%s, "includes count of reports and reports in fixed order"
stdout_like { $e->end_summary_failures } qr%The following 2 reports had problems sending:\nCouncil of the Thousand \(2\): $id2, $id1.*report/$id2.*report/$id1%s, "includes count of reports and reports in fixed order"

};

Expand Down

0 comments on commit 5c40ee1

Please sign in to comment.