summaryrefslogtreecommitdiffstats
path: root/extensions/Push/lib/BacklogQueue.pm
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/Push/lib/BacklogQueue.pm')
-rw-r--r--extensions/Push/lib/BacklogQueue.pm138
1 files changed, 66 insertions, 72 deletions
diff --git a/extensions/Push/lib/BacklogQueue.pm b/extensions/Push/lib/BacklogQueue.pm
index a7200c688..17d0a188f 100644
--- a/extensions/Push/lib/BacklogQueue.pm
+++ b/extensions/Push/lib/BacklogQueue.pm
@@ -15,74 +15,67 @@ use Bugzilla;
use Bugzilla::Extension::Push::BacklogMessage;
sub new {
- my ($class, $connector) = @_;
- my $self = {};
- bless($self, $class);
- $self->{connector} = $connector;
- return $self;
+ my ($class, $connector) = @_;
+ my $self = {};
+ bless($self, $class);
+ $self->{connector} = $connector;
+ return $self;
}
sub count {
- my ($self) = @_;
- my $dbh = Bugzilla->dbh;
- return $dbh->selectrow_array("
+ my ($self) = @_;
+ my $dbh = Bugzilla->dbh;
+ return $dbh->selectrow_array("
SELECT COUNT(*)
FROM push_backlog
- WHERE connector = ?",
- undef,
- $self->{connector});
+ WHERE connector = ?", undef, $self->{connector});
}
sub oldest {
- my ($self) = @_;
- my @messages = $self->list(
- limit => 1,
- filter => 'AND ((next_attempt_ts IS NULL) OR (next_attempt_ts <= NOW()))',
- );
- return scalar(@messages) ? $messages[0] : undef;
+ my ($self) = @_;
+ my @messages = $self->list(
+ limit => 1,
+ filter => 'AND ((next_attempt_ts IS NULL) OR (next_attempt_ts <= NOW()))',
+ );
+ return scalar(@messages) ? $messages[0] : undef;
}
sub by_id {
- my ($self, $id) = @_;
- my @messages = $self->list(
- limit => 1,
- filter => "AND (log.id = $id)",
- );
- return scalar(@messages) ? $messages[0] : undef;
+ my ($self, $id) = @_;
+ my @messages = $self->list(limit => 1, filter => "AND (log.id = $id)",);
+ return scalar(@messages) ? $messages[0] : undef;
}
sub list {
- my ($self, %args) = @_;
- $args{limit} ||= 10;
- $args{filter} ||= '';
- my @result;
- my $dbh = Bugzilla->dbh;
+ my ($self, %args) = @_;
+ $args{limit} ||= 10;
+ $args{filter} ||= '';
+ my @result;
+ my $dbh = Bugzilla->dbh;
- my $filter_sql = $args{filter} || '';
- my $sth = $dbh->prepare("
+ my $filter_sql = $args{filter} || '';
+ my $sth = $dbh->prepare("
SELECT log.id, message_id, push_ts, payload, change_set, routing_key, attempt_ts, log.attempts
FROM push_backlog log
LEFT JOIN push_backoff off ON off.connector = log.connector
- WHERE log.connector = ? ".
- $args{filter} . "
- ORDER BY push_ts " .
- $dbh->sql_limit($args{limit})
- );
- $sth->execute($self->{connector});
- while (my $row = $sth->fetchrow_hashref()) {
- push @result, Bugzilla::Extension::Push::BacklogMessage->new({
- id => $row->{id},
- message_id => $row->{message_id},
- push_ts => $row->{push_ts},
- payload => $row->{payload},
- change_set => $row->{change_set},
- routing_key => $row->{routing_key},
- connector => $self->{connector},
- attempt_ts => $row->{attempt_ts},
- attempts => $row->{attempts},
- });
- }
- return @result;
+ WHERE log.connector = ? " . $args{filter} . "
+ ORDER BY push_ts " . $dbh->sql_limit($args{limit}));
+ $sth->execute($self->{connector});
+ while (my $row = $sth->fetchrow_hashref()) {
+ push @result,
+ Bugzilla::Extension::Push::BacklogMessage->new({
+ id => $row->{id},
+ message_id => $row->{message_id},
+ push_ts => $row->{push_ts},
+ payload => $row->{payload},
+ change_set => $row->{change_set},
+ routing_key => $row->{routing_key},
+ connector => $self->{connector},
+ attempt_ts => $row->{attempt_ts},
+ attempts => $row->{attempts},
+ });
+ }
+ return @result;
}
#
@@ -90,39 +83,40 @@ sub list {
#
sub backoff {
- my ($self) = @_;
- if (!$self->{backoff}) {
- my $ra = Bugzilla::Extension::Push::Backoff->match({
- connector => $self->{connector}
+ my ($self) = @_;
+ if (!$self->{backoff}) {
+ my $ra
+ = Bugzilla::Extension::Push::Backoff->match({connector => $self->{connector}
+ });
+ if (@$ra) {
+ $self->{backoff} = $ra->[0];
+ }
+ else {
+ $self->{backoff}
+ = Bugzilla::Extension::Push::Backoff->create({connector => $self->{connector}
});
- if (@$ra) {
- $self->{backoff} = $ra->[0];
- } else {
- $self->{backoff} = Bugzilla::Extension::Push::Backoff->create({
- connector => $self->{connector}
- });
- }
}
- return $self->{backoff};
+ }
+ return $self->{backoff};
}
sub reset_backoff {
- my ($self) = @_;
- my $backoff = $self->backoff;
- $backoff->reset();
- $backoff->update();
+ my ($self) = @_;
+ my $backoff = $self->backoff;
+ $backoff->reset();
+ $backoff->update();
}
sub inc_backoff {
- my ($self) = @_;
- my $backoff = $self->backoff;
- $backoff->inc();
- $backoff->update();
+ my ($self) = @_;
+ my $backoff = $self->backoff;
+ $backoff->inc();
+ $backoff->update();
}
sub connector {
- my ($self) = @_;
- return $self->{connector};
+ my ($self) = @_;
+ return $self->{connector};
}
1;