diff options
author | Struan Donald <struan@exo.org.uk> | 2012-04-03 16:48:11 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2012-04-03 16:48:11 +0100 |
commit | f531995b83e8448de25adab411673ec38e555385 (patch) | |
tree | 0d8090d554de7879963f4e1dfcd26c3bc7338dd0 | |
parent | 8bfb404c462cdc950b946a5de73152c2e8a7e502 (diff) |
update send failed data if fail to send a report
add code in to save success and errors
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/EastHants.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/London.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 3 |
6 files changed, 31 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index ae184e87b..9e4c63902 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -232,8 +232,8 @@ sub send_reports { } ); my (%notgot, %note); - my $s = FixMyStreet::SendReport->new(); - my $senders = $s->get_senders; + my $send_report = FixMyStreet::SendReport->new(); + my $senders = $send_report->get_senders; while (my $row = $unsent->next) { @@ -370,14 +370,6 @@ sub send_reports { ); } - # Special case for this parish council - # if ($address && $address =~ /Sprowston/ && $row->council == 2233 && $row->category eq 'Street lighting') { - # $h{councils_name} = 'Sprowston Parish Council'; - # my $e = 'parishclerk' . '@' . 'sprowston-pc.gov.uk'; - # @to = ( [ $e, $h{councils_name} ] ); - # @recips = ($e); - # } - # Multiply results together, so one success counts as a success. my $result = -1; @@ -392,6 +384,14 @@ sub send_reports { whensent => \'ms_current_timestamp()', lastupdate => \'ms_current_timestamp()', } ); + } else { + my @errors; + for my $sender ( keys %reporters ) { + unless ( $reporters{ $sender }->sucess ) { + push @errors, $reporters{ $sender }->error; + } + } + $row->update_send_failed( join( '|', @errors ) ); } } diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm index 84a89f877..e3b0b389c 100644 --- a/perllib/FixMyStreet/SendReport.pm +++ b/perllib/FixMyStreet/SendReport.pm @@ -7,8 +7,10 @@ use Module::Pluggable search_path => __PACKAGE__, require => 1; -has 'councils' => (is => 'rw', isa => 'HashRef', default => sub { {} } ); -has 'to' => (is => 'rw', isa => 'ArrayRef', default => sub { [] } ); +has 'councils' => ( is => 'rw', isa => 'HashRef', default => sub { {} } ); +has 'to' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } ); +has 'success' => ( is => 'rw', isa => 'Bool', default => 0 ); +has 'error' => ( is => 'rw', isa => 'Str', default => '' ); sub get_senders { my $self = shift; diff --git a/perllib/FixMyStreet/SendReport/EastHants.pm b/perllib/FixMyStreet/SendReport/EastHants.pm index 61c38e591..681a9d4c4 100644 --- a/perllib/FixMyStreet/SendReport/EastHants.pm +++ b/perllib/FixMyStreet/SendReport/EastHants.pm @@ -32,7 +32,7 @@ EOF sub send { return if mySociety::Config::get('STAGING_SITE'); - my ( $row, $h, $to, $template, $recips, $nomail ) = @_; + my ( $self, $row, $h, $to, $template, $recips, $nomail ) = @_; # FIXME: should not recreate this each time my $eh_service; @@ -53,7 +53,9 @@ sub send { } otherwise { my $e = shift; print "Caught an error: $e\n"; + $self->error( "Error sending to East Hants: $e" ); }; + $self->success( !$return ); return $return; } diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 0b8ac8115..239bee715 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -4,6 +4,8 @@ use Moose; BEGIN { extends 'FixMyStreet::SendReport'; } +use mySociety::EmailUtil; + sub build_recipient_list { my $self = shift; my $row = shift; @@ -66,6 +68,12 @@ sub send { $nomail ); + if ( $result == mySociety::EmailUtil::EMAIL_SUCCESS ) { + $self->success(1); + } else { + $self->error( 'Failed to send email' ); + } + return $result; } diff --git a/perllib/FixMyStreet/SendReport/London.pm b/perllib/FixMyStreet/SendReport/London.pm index 9296f2446..58ecb2375 100644 --- a/perllib/FixMyStreet/SendReport/London.pm +++ b/perllib/FixMyStreet/SendReport/London.pm @@ -33,7 +33,7 @@ EOF sub send { return if mySociety::Config::get('STAGING_SITE'); - my ( $row, $h, $to, $template, $recips, $nomail ) = @_; + my ( $self, $row, $h, $to, $template, $recips, $nomail ) = @_; $h->{message} = construct_message( %$h ); my $phone = $h->{phone}; @@ -80,6 +80,7 @@ sub send { my $out = $response->content; if ($response->code ne 200) { print "Failed to post $h->{id} to London API, response was " . $response->code . " $out\n"; + $self->error( "Failed to post $h->{id} to London API, response was " . $response->code . " $out" ); return 1; } my ($id) = $out =~ /<caseid>(.*?)<\/caseid>/; @@ -90,6 +91,7 @@ sub send { $row->external_id( $id ); $row->external_body( $org ); $row->external_team( $team ); + $self->success(1); return 0; } diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index cb41de336..beed04658 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -54,6 +54,7 @@ sub send { if ( $resp ) { $row->external_id( $resp ); $result *= 0; + $self->success( 1 ) } else { $result *= 1; # temporary fix to resolve some issues with west berks @@ -63,6 +64,8 @@ sub send { } } + $self->error( 'Failed to send over Open311' ) unless $self->success; + return $result; } |