summaryrefslogtreecommitdiffstats
path: root/extensions/Push/lib/Backoff.pm
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/Push/lib/Backoff.pm')
-rw-r--r--extensions/Push/lib/Backoff.pm82
1 files changed, 42 insertions, 40 deletions
diff --git a/extensions/Push/lib/Backoff.pm b/extensions/Push/lib/Backoff.pm
index 0436cdf14..070adfc29 100644
--- a/extensions/Push/lib/Backoff.pm
+++ b/extensions/Push/lib/Backoff.pm
@@ -26,21 +26,21 @@ use Bugzilla::Util;
# initialisation
#
-use constant DB_TABLE => 'push_backoff';
+use constant DB_TABLE => 'push_backoff';
use constant DB_COLUMNS => qw(
- id
- connector
- next_attempt_ts
- attempts
+ id
+ connector
+ next_attempt_ts
+ attempts
);
use constant UPDATE_COLUMNS => qw(
- next_attempt_ts
- attempts
+ next_attempt_ts
+ attempts
);
use constant VALIDATORS => {
- connector => \&_check_connector,
- next_attempt_ts => \&_check_next_attempt_ts,
- attempts => \&_check_attempts,
+ connector => \&_check_connector,
+ next_attempt_ts => \&_check_next_attempt_ts,
+ attempts => \&_check_attempts,
};
use constant LIST_ORDER => 'next_attempt_ts';
@@ -48,16 +48,16 @@ use constant LIST_ORDER => 'next_attempt_ts';
# accessors
#
-sub connector { return $_[0]->{'connector'}; }
+sub connector { return $_[0]->{'connector'}; }
sub next_attempt_ts { return $_[0]->{'next_attempt_ts'}; }
-sub attempts { return $_[0]->{'attempts'}; }
+sub attempts { return $_[0]->{'attempts'}; }
sub next_attempt_time {
- my ($self) = @_;
- if (!exists $self->{'next_attempt_time'}) {
- $self->{'next_attempt_time'} = datetime_from($self->next_attempt_ts)->epoch;
- }
- return $self->{'next_attempt_time'};
+ my ($self) = @_;
+ if (!exists $self->{'next_attempt_time'}) {
+ $self->{'next_attempt_time'} = datetime_from($self->next_attempt_ts)->epoch;
+ }
+ return $self->{'next_attempt_time'};
}
#
@@ -65,25 +65,26 @@ sub next_attempt_time {
#
sub reset {
- my ($self) = @_;
- $self->{next_attempt_ts} = Bugzilla->dbh->selectrow_array('SELECT NOW()');
- $self->{attempts} = 0;
- INFO( sprintf 'resetting backoff for %s', $self->connector );
+ my ($self) = @_;
+ $self->{next_attempt_ts} = Bugzilla->dbh->selectrow_array('SELECT NOW()');
+ $self->{attempts} = 0;
+ INFO(sprintf 'resetting backoff for %s', $self->connector);
}
sub inc {
- my ($self) = @_;
- my $dbh = Bugzilla->dbh;
-
- my $attempts = $self->attempts + 1;
- my $seconds = $attempts <= 4 ? 5 ** $attempts : 15 * 60;
- my ($date) = $dbh->selectrow_array("SELECT " . $dbh->sql_date_math('NOW()', '+', $seconds, 'SECOND'));
-
- $self->{next_attempt_ts} = $date;
- $self->{attempts} = $attempts;
- INFO(
- sprintf 'setting next attempt for %s to %s (attempt %s)', $self->connector, $date, $attempts
- );
+ my ($self) = @_;
+ my $dbh = Bugzilla->dbh;
+
+ my $attempts = $self->attempts + 1;
+ my $seconds = $attempts <= 4 ? 5**$attempts : 15 * 60;
+ my ($date)
+ = $dbh->selectrow_array(
+ "SELECT " . $dbh->sql_date_math('NOW()', '+', $seconds, 'SECOND'));
+
+ $self->{next_attempt_ts} = $date;
+ $self->{attempts} = $attempts;
+ INFO(sprintf 'setting next attempt for %s to %s (attempt %s)',
+ $self->connector, $date, $attempts);
}
#
@@ -91,19 +92,20 @@ sub inc {
#
sub _check_connector {
- my ($invocant, $value) = @_;
- Bugzilla->push_ext->connectors->exists($value) || ThrowCodeError('push_invalid_connector');
- return $value;
+ my ($invocant, $value) = @_;
+ Bugzilla->push_ext->connectors->exists($value)
+ || ThrowCodeError('push_invalid_connector');
+ return $value;
}
sub _check_next_attempt_ts {
- my ($invocant, $value) = @_;
- return $value || Bugzilla->dbh->selectrow_array('SELECT NOW()');
+ my ($invocant, $value) = @_;
+ return $value || Bugzilla->dbh->selectrow_array('SELECT NOW()');
}
sub _check_attempts {
- my ($invocant, $value) = @_;
- return $value || 0;
+ my ($invocant, $value) = @_;
+ return $value || 0;
}
1;