diff options
author | Matthew Somerville <matthew@mysociety.org> | 2013-05-02 18:48:39 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2013-05-02 20:48:05 +0100 |
commit | 9b6a6fd63daacf67cddb4f5ab7bbcd0375082696 (patch) | |
tree | 2f832a82aac5ce6050090a3d250b7bec93274902 /perllib/FixMyStreet/SendReport.pm | |
parent | c4b3f85594e91c772011dffef2da2498ee5c8a5e (diff) |
Consolidate sending backoff for different types of sender.
Diffstat (limited to 'perllib/FixMyStreet/SendReport.pm')
-rw-r--r-- | perllib/FixMyStreet/SendReport.pm | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm index f8901c6f8..5087c7ead 100644 --- a/perllib/FixMyStreet/SendReport.pm +++ b/perllib/FixMyStreet/SendReport.pm @@ -12,13 +12,22 @@ has 'bodies' => ( is => 'rw', isa => 'ArrayRef', 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 => '' ); -has 'skipped' => ( 'is' => 'rw', isa => 'Str', default => '' ); has 'unconfirmed_counts' => ( 'is' => 'rw', isa => 'HashRef', default => sub { {} } ); has 'unconfirmed_notes' => ( 'is' => 'rw', isa => 'HashRef', default => sub { {} } ); sub should_skip { - return 0; + my $self = shift; + my $row = shift; + + return 0 unless $row->send_fail_count; + + my $tz = DateTime::TimeZone->new( name => 'local' ); + my $now = DateTime->now( time_zone => $tz ); + my $diff = $now - $row->send_fail_timestamp; + + my $backoff = $row->send_fail_count > 1 ? 30 : 5; + return $diff->in_units( 'minutes' ) < $backoff; } sub get_senders { |