aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-05-19 15:14:14 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-05-19 15:47:53 +0100
commit082f2c31c8dc94fe5e2492b0dd3ad65c4db9f2c1 (patch)
tree2c87a29267be472c02a9b34d0c7583d4475d2e97
parent61eb613ddc31943e9d6504050c0e96f91340f752 (diff)
[Bristol] Switch warn threshold to five failures.
-rw-r--r--perllib/Open311.pm26
-rw-r--r--t/open311.t6
2 files changed, 25 insertions, 7 deletions
diff --git a/perllib/Open311.pm b/perllib/Open311.pm
index c1323acfa..b52cee0ea 100644
--- a/perllib/Open311.pm
+++ b/perllib/Open311.pm
@@ -59,6 +59,24 @@ sub get_service_meta_info {
return $self->_get_xml_object( $service_meta_xml );
}
+sub to_bristol {
+ my $problem = shift;
+ return unless $problem->cobrand =~ /fixmystreet|bristol/;
+ my $bodies = $problem->bodies;
+ return unless %$bodies;
+ my $body = (values %$bodies)[0];
+ return unless $body->areas->{2561};
+ return 1;
+}
+
+sub warn_failure {
+ my ($obj, $problem) = @_;
+ # Special case a poorly behaving Open311 server
+ my $threshold = 1;
+ $threshold = 5 if to_bristol($problem || $obj);
+ return $obj->send_fail_count && $obj->send_fail_count == $threshold;
+}
+
sub send_service_request {
my $self = shift;
my $problem = shift;
@@ -83,10 +101,10 @@ sub send_service_request {
}
warn sprintf( "Failed to submit problem %s over Open311, response\n: %s\n%s", $problem->id, $response, $self->debug_details )
- if $problem->send_fail_count && $problem->send_fail_count == 2;
+ if warn_failure($problem);
} else {
warn sprintf( "Failed to submit problem %s over Open311, details:\n%s", $problem->id, $self->error)
- if $problem->send_fail_count && $problem->send_fail_count == 2;
+ if warn_failure($problem);
}
return 0;
}
@@ -259,10 +277,10 @@ sub post_service_request_update {
}
warn sprintf( "Failed to submit comment %s over Open311, response - %s\n%s\n", $comment->id, $response, $self->debug_details )
- if $comment->send_fail_count && $comment->send_fail_count == 2;
+ if warn_failure($comment, $comment->problem);
} else {
warn sprintf( "Failed to submit comment %s over Open311, details\n%s\n", $comment->id, $self->error)
- if $comment->send_fail_count && $comment->send_fail_count == 2;
+ if warn_failure($comment, $comment->problem);
}
return 0;
}
diff --git a/t/open311.t b/t/open311.t
index e6ea9b6fc..06dec6a6f 100644
--- a/t/open311.t
+++ b/t/open311.t
@@ -44,7 +44,7 @@ for my $sfc (0..2) {
} );
my $expected_error = qr{Failed to submit problem 1 over Open311}ism;
- if ($sfc == 2) {
+ if ($sfc == 1) {
warning_like {$o2->send_service_request( $p, { url => 'http://example.com/' }, 1 )} $expected_error, 'warning generated on failed call';
} else {
warning_like {$o2->send_service_request( $p, { url => 'http://example.com/' }, 1 )} undef, 'no warning generated on failed call';
@@ -578,8 +578,8 @@ for my $test (
};
}
-$problem->send_fail_count(2);
-$comment->send_fail_count(2);
+$problem->send_fail_count(1);
+$comment->send_fail_count(1);
subtest 'No request id in reponse' => sub {
my $results;