summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorMars <mfogels@gmail.com>2018-08-16 23:39:19 +0200
committerDylan William Hardison <dylan@hardison.net>2018-08-16 23:39:19 +0200
commitae9885389d3ce428f24e0352814b70b099fadb95 (patch)
treefdbc45867bc5987faa640db7178f108dd574b7ad /extensions
parentec87e5310ad038abe4b2b329897638d866bf549a (diff)
downloadbugzilla-ae9885389d3ce428f24e0352814b70b099fadb95.tar.gz
bugzilla-ae9885389d3ce428f24e0352814b70b099fadb95.tar.xz
Bug 1480878 - Monitor the health of Push connector job processing
Diffstat (limited to 'extensions')
-rw-r--r--extensions/Push/lib/Push.pm70
1 files changed, 48 insertions, 22 deletions
diff --git a/extensions/Push/lib/Push.pm b/extensions/Push/lib/Push.pm
index 670b2aa56..ab640da81 100644
--- a/extensions/Push/lib/Push.pm
+++ b/extensions/Push/lib/Push.pm
@@ -8,8 +8,7 @@
package Bugzilla::Extension::Push::Push;
use 5.10.1;
-use strict;
-use warnings;
+use Moo;
use Bugzilla::Logging;
use Bugzilla::Extension::Push::BacklogMessage;
@@ -23,22 +22,12 @@ use Bugzilla::Extension::Push::Option;
use Bugzilla::Extension::Push::Queue;
use Bugzilla::Extension::Push::Util;
use DateTime;
+use Try::Tiny;
-sub new {
- my ($class) = @_;
- my $self = {};
- bless($self, $class);
- $self->{is_daemon} = 0;
- return $self;
-}
-
-sub is_daemon {
- my ($self, $value) = @_;
- if (defined $value) {
- $self->{is_daemon} = $value ? 1 : 0;
- }
- return $self->{is_daemon};
-}
+has 'is_daemon' => (
+ is => 'rw',
+ default => 0,
+);
sub start {
my ($self) = @_;
@@ -50,12 +39,49 @@ sub start {
$connector->backlog->reset_backoff();
}
- while(1) {
- if ($self->_dbh_check()) {
- $self->_reload();
- $self->push();
+ my $pushd_loop = IO::Async::Loop->new;
+ my $main_timer = IO::Async::Timer::Periodic->new(
+ first_interval => 0,
+ interval => POLL_INTERVAL_SECONDS,
+ reschedule => 'drift',
+ on_tick => sub {
+ if ( $self->_dbh_check() ) {
+ $self->_reload();
+ try {
+ $self->push();
+ }
+ catch {
+ FATAL($_);
+ };
+ }
+ },
+ );
+ if ( Bugzilla->datadog ) {
+ my $dog_timer = IO::Async::Timer::Periodic->new(
+ interval => 120,
+ reschedule => 'drift',
+ on_tick => sub { $self->heartbeat },
+ );
+ $pushd_loop->add($dog_timer);
+ $dog_timer->start;
+ }
+
+ $pushd_loop->add($main_timer);
+ $main_timer->start;
+ $pushd_loop->run;
+}
+
+sub heartbeat {
+ my ($self) = @_;
+ my $dd = Bugzilla->datadog('bugzilla.pushd');
+
+ $dd->gauge('scheduled_jobs', Bugzilla->dbh->selectrow_array('SELECT COUNT(*) FROM push'));
+
+ foreach my $connector ($self->connectors->list) {
+ if ($connector->enabled) {
+ my $lcname = lc $connector->name;
+ $dd->gauge("${lcname}.backlog", Bugzilla->dbh->selectrow_array('SELECT COUNT(*) FROM push_backlog WHERE connector = ?', undef, $connector->name));
}
- sleep(POLL_INTERVAL_SECONDS);
}
}