diff options
author | Struan Donald <struan@exo.org.uk> | 2012-03-22 17:38:09 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2012-03-22 17:38:09 +0000 |
commit | 832ee711e4b741196146b0218678d34849aa82ff (patch) | |
tree | f16e0a706a39e565eb13661b29b6ff3e0b1dce7a | |
parent | 420c6becdb08d90da03f222a492893cd993772a1 (diff) |
add in retry count code
-rwxr-xr-x | bin/send-reports | 29 | ||||
-rw-r--r-- | db/schema.sql | 7 | ||||
-rw-r--r-- | db/schema_0014-add_send_fail_columns_to_problem.sql | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 10 |
4 files changed, 53 insertions, 3 deletions
diff --git a/bin/send-reports b/bin/send-reports index 7ccdf1dc4..b2320bb1d 100755 --- a/bin/send-reports +++ b/bin/send-reports @@ -30,6 +30,9 @@ use mySociety::Web qw(ent); use Open311; +# maximum number of webservice attempts to send before not trying any more (XXX may be better in config?) +use constant SEND_FAIL_RETRIES_CUTOFF => 3; + # specific council numbers use constant COUNCIL_ID_EAST_HANTS => 2330; @@ -540,3 +543,29 @@ sub london_lookup { return $str; } + +# tests send_fail_count agains cutoff limit +# args: problem (row from problem db) +# returns false if there is no cutoff, otherwise error message +sub does_exceed_cutoff_limit { + my ($problem, $council_name) = @_; + my $err_msg = ""; + if ($problem->send_fail_count >= SEND_FAIL_RETRIES_CUTOFF) { + $council_name &&= " to $council_name"; + $err_msg = "skipped: problem id=" . $problem->id . " send$council_name has failed " + . $problem->send_fail_count . " times, cutoff is " . SEND_FAIL_RETRIES_CUTOFF; + } + return $err_msg; +} + +# update_send_fail_data records the failure (of a webservice send) +# args: problem (row from problem db) +# returns: no return value (updates record) +sub update_send_fail_data { + my ($problem, $err_msg) = @_; + $problem->update( { + send_fail_count => $problem->send_fail_count + 1, + send_fail_timestamp => \'ms_current_timestamp()', + send_fail_reason => $err_msg + } ); +} diff --git a/db/schema.sql b/db/schema.sql index ab323ee1a..d9faa4aac 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -189,7 +189,12 @@ create table problem ( send_questionnaire boolean not null default 't', extra text, -- extra fields required for open311 flagged boolean not null default 'f', - geocode bytea + geocode bytea, + + -- logging sending failures (used by webservices) + send_fail_count integer not null default 0, + send_fail_reason text, + send_fail_timestamp timestamp ); create index problem_state_latitude_longitude_idx on problem(state, latitude, longitude); create index problem_user_id_idx on problem ( user_id ); diff --git a/db/schema_0014-add_send_fail_columns_to_problem.sql b/db/schema_0014-add_send_fail_columns_to_problem.sql new file mode 100644 index 000000000..369c4118d --- /dev/null +++ b/db/schema_0014-add_send_fail_columns_to_problem.sql @@ -0,0 +1,10 @@ +begin; + +ALTER table problem + ADD column send_fail_count integer not null default 0; +ALTER table problem + ADD column send_fail_reason text; +ALTER table problem + ADD column send_fail_timestamp timestamp; + +commit; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index ce7488703..8c479953b 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -84,6 +84,12 @@ __PACKAGE__->add_columns( { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "geocode", { data_type => "bytea", is_nullable => 1 }, + "send_fail_count", + { data_type => "integer", is_nullable => 1 }, + "send_fail_reason", + { data_type => "text", is_nullable => 1 }, + "send_fail_timestamp", + { data_type => "timestamp", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( @@ -106,8 +112,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-09-19 14:38:43 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nq8Ufn/SEoDGSrrGlHIxag +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-16 10:08:56 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:VODeZlWk8l/+IzBBlRNV0A # Add fake relationship to stored procedure table __PACKAGE__->has_one( |