From 755bc194dcea3481fa41b5884a98a5aa086fe09e Mon Sep 17 00:00:00 2001 From: Israel Madueme Date: Thu, 5 Apr 2018 16:23:43 -0400 Subject: Bug 1449282 - add jobqueue_status api --- Bugzilla/WebService/Bugzilla.pm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'Bugzilla/WebService/Bugzilla.pm') diff --git a/Bugzilla/WebService/Bugzilla.pm b/Bugzilla/WebService/Bugzilla.pm index 0d0393c28..145502445 100644 --- a/Bugzilla/WebService/Bugzilla.pm +++ b/Bugzilla/WebService/Bugzilla.pm @@ -13,7 +13,10 @@ use warnings; use base qw(Bugzilla::WebService); use Bugzilla::Constants; +use Bugzilla::Error; +use Bugzilla::Logging; use Bugzilla::Util qw(datetime_from); +use Try::Tiny; use DateTime; @@ -28,6 +31,7 @@ use constant READ_ONLY => qw( timezone time version + jobqueue_status ); use constant PUBLIC_METHODS => qw( @@ -35,6 +39,7 @@ use constant PUBLIC_METHODS => qw( time timezone version + jobqueue_status ); sub version { @@ -80,6 +85,39 @@ sub time { }; } +sub jobqueue_status { + my ( $self, $params ) = @_; + + Bugzilla->login(LOGIN_REQUIRED); + + my $dbh = Bugzilla->dbh; + my $query = q{ + SELECT + COUNT(*) AS total, + COALESCE( + (SELECT COUNT(*) + FROM ts_error + WHERE ts_error.jobid = j.jobid + ) + , 0) AS errors + FROM ts_job j + INNER JOIN ts_funcmap f + ON f.funcid = j.funcid; + }; + + my $status; + try { + $status = $dbh->selectrow_hashref($query); + $status->{errors} = 0 + $status->{errors}; + $status->{total} = 0 + $status->{total}; + } catch { + ERROR($_); + ThrowCodeError('jobqueue_status_error'); + }; + + return $status; +} + 1; __END__ -- cgit v1.2.3-24-g4f1b