Skip to content

Commit

Permalink
Merge remote-tracking branches 'origin/fetch-tweaks' and 'origin/skip…
Browse files Browse the repository at this point in the history
…-wait-mark-failure'
  • Loading branch information
dracos committed Jan 10, 2022
3 parents 1f9079e + 0e34d57 + 97158e3 commit 2d20f8d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
- Development improvements:
- Default make_css to `web/cobrands` rather than `web`.
- Ability to pass custom arguments (eg: SSL config) to server when running via Docker
- Allow bin/fetch start/end times to be fractional.
- Open311 improvements:
- Increase default timeout.

* v4.0 (3rd December 2021)
- Front end improvements:
Expand Down
4 changes: 2 additions & 2 deletions bin/fetch
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ my ($opts, $usage) = describe_options(
'%c %o',
['reports', 'fetch reports'],
['updates', 'fetch updates'],
['start|s:i', 'start time to use (hours before now), defaults to one (reports) or two (updates)' ],
['end|e:i', 'end time to use (hours before now), defaults to zero' ],
['start|s:f', 'start time to use (hours before now), defaults to one (reports) or two (updates)' ],
['end|e:f', 'end time to use (hours before now), defaults to zero' ],
['body|b:s', 'body name to only fetch this body' ],
['verbose|v', 'more verbose output'],
['help|h', "print usage message and exit" ],
Expand Down
11 changes: 11 additions & 0 deletions perllib/FixMyStreet/DB/Result/Comment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ sub moderation_filter {
{ problem_id => $self->problem_id };
}

sub update_send_failed {
my $self = shift;
my $msg = shift;

$self->update( {
send_fail_count => $self->send_fail_count + 1,
send_fail_timestamp => \'current_timestamp',
send_fail_reason => $msg
} );
}

=head2 meta_line
Returns a string to be used on a report update, describing some of the metadata
Expand Down
2 changes: 1 addition & 1 deletion perllib/Open311.pm
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ sub _request {

sub _make_request {
my ($self, $req) = @_;
my $ua = LWP::UserAgent->new;
my $ua = LWP::UserAgent->new( timeout => 300 );
my $res = $ua->request( $req );
return $res;
}
Expand Down
11 changes: 5 additions & 6 deletions perllib/Open311/PostServiceRequestUpdates.pm
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ sub process_update {
# Some cobrands (e.g. Buckinghamshire) don't want to receive updates
# from anyone except the original problem reporter.
if (my $skip = $cobrand->call_hook(should_skip_sending_update => $comment)) {
if ($skip ne 'WAIT' && !defined $comment->get_extra_metadata('cobrand_skipped_sending')) {
if ($skip eq 'WAIT') {
# Mark this as a failure, so that it is not constantly retried
$comment->update_send_failed("Skipping posting due to wait");
} elsif (!defined $comment->get_extra_metadata('cobrand_skipped_sending')) {
$comment->set_extra_metadata(cobrand_skipped_sending => 1);
$comment->update;
}
Expand All @@ -137,11 +140,7 @@ sub process_update {
} );
$self->log($comment, 'Send successful');
} else {
$comment->update( {
send_fail_count => $comment->send_fail_count + 1,
send_fail_timestamp => \'current_timestamp',
send_fail_reason => "Failed to post over Open311\n\n" . $o->error,
} );
$comment->update_send_failed("Failed to post over Open311\n\n" . $o->error);
$self->log($comment, 'Send failed');
}
}
Expand Down
3 changes: 2 additions & 1 deletion t/open311/post-service-request-updates.t
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ subtest 'Send comments' => sub {
$c1->discard_changes;
is $c1->extra->{title}, "MRS", 'Title set on Bromley update';
$c2->discard_changes;
is $c2->send_fail_count, 0, 'Oxfordshire update skipped entirely';
is $c2->send_fail_count, 1, 'Oxfordshire update skipped entirely, still logs as failure';
$c2->update({ send_fail_count => 0 });

Open311->_inject_response('/servicerequestupdates.xml', "", 500);
$oxon_other->update({ email => 'Alloy-OTHER' });
Expand Down

0 comments on commit 2d20f8d

Please sign in to comment.