aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2012-03-26 12:07:12 +0100
committerStruan Donald <struan@exo.org.uk>2012-03-26 12:07:12 +0100
commit3ef282bed8cb0ff85b2a03ce5e622c3a68c78909 (patch)
tree5faf52a5923ed7c9570bfab7a778d00bcc2d349a
parent437e03329eba224258a37c9657fbbc5778e38aea (diff)
initial bromley retry code for problems
-rwxr-xr-xbin/send-reports42
1 files changed, 30 insertions, 12 deletions
diff --git a/bin/send-reports b/bin/send-reports
index daf091790..1b93f8c5a 100755
--- a/bin/send-reports
+++ b/bin/send-reports
@@ -302,6 +302,22 @@ while (my $row = $unsent->next) {
foreach my $conf ( @open311_councils ) {
print 'posting to end point for ' . $conf->area_id . "\n" if $verbose;
+ # Extra bromley fields
+ if ( $row->council =~ /2482/ ) {
+ if ( $row->send_fail_count > 0 ) {
+ next if bromley_retry_timeout( $row );
+ }
+
+ my $extra = $row->extra;
+ push @$extra, { name => 'northing', value => $h{northing} };
+ push @$extra, { name => 'easting', value => $h{easting} };
+ push @$extra, { name => 'report_url', value => $h{url} };
+ push @$extra, { name => 'service_request_id', value => $row->id };
+ push @$extra, { name => 'report_title', value => $row->title };
+ push @$extra, { name => 'public_anonymity_required', value => $row->anonymous ? 'TRUE' : 'FALSE' };
+ $row->extra( $extra );
+ }
+
my $contact = FixMyStreet::App->model("DB::Contact")->find( {
deleted => 0,
area_id => $conf->area_id,
@@ -324,18 +340,6 @@ while (my $row = $unsent->next) {
$row->user->name( $row->user->id . ' ' . $row->user->name );
}
- # Extra bromley fields
- if ( $row->council =~ /2482/ ) {
- my $extra = $row->extra;
- push @$extra, { name => 'northing', value => $h{northing} };
- push @$extra, { name => 'easting', value => $h{easting} };
- push @$extra, { name => 'report_url', value => $h{url} };
- push @$extra, { name => 'service_request_id', value => $row->id };
- push @$extra, { name => 'report_title', value => $row->title };
- push @$extra, { name => 'public_anonymity_required', value => $row->anonymous ? 'TRUE' : 'FALSE' };
- $row->extra( $extra );
- }
-
my $resp = $open311->send_service_request( $row, \%h, $contact->email );
# make sure we don't save user changes from above
@@ -348,6 +352,7 @@ while (my $row = $unsent->next) {
$result *= 0;
} else {
$result *= 1;
+ update_send_fail_data( $row, 'Open311 failed' );
# temporary fix to resolve some issues with west berks
if ( $row->council =~ /2619/ ) {
$result *= 0;
@@ -584,3 +589,16 @@ sub update_send_fail_data {
send_fail_reason => $err_msg
} );
}
+
+sub bromley_retry_timeout {
+ my $row = shift;
+
+ my $tz = DateTime::TimeZone->new( name => 'local' );
+ my $now = DateTime->now( time_zone => $tz );
+ my $diff = $now - $row->send_fail_timestamp;
+ if ( $diff->minutes < 30 ) {
+ return 1;
+ }
+
+ return 0;
+}