]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1449282 - add jobqueue_status api
authorIsrael Madueme <purelogiq@gmail.com>
Thu, 5 Apr 2018 20:23:43 +0000 (16:23 -0400)
committerDylan William Hardison <dylan@hardison.net>
Thu, 5 Apr 2018 20:23:43 +0000 (16:23 -0400)
Bugzilla/WebService/Bugzilla.pm
Bugzilla/WebService/Constants.pm
Bugzilla/WebService/Server/REST/Resources/Bugzilla.pm
docs/en/rst/api/core/v1/bugzilla.rst
template/en/default/global/code-error.html.tmpl

index 0d0393c285f1bed9b857d93cc949c76fe5727c17..1455024457a69e9e0bde774619772922cf61797c 100644 (file)
@@ -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__
index 93fddfc2b607318d4aa823f3967ed128f5e4e263..71435c13a523d5dca6a3193d7e8cb8db0323a104 100644 (file)
@@ -199,6 +199,9 @@ use constant WS_ERROR_CODE => {
     # BugUserLastVisited errors
     user_not_involved => 1300,
 
+    # Job queue errors 1400-1500
+    jobqueue_status_error => 1400,
+
     # Errors thrown by the WebService itself. The ones that are negative
     # conform to http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
     xmlrpc_invalid_value => -32600,
index a8f3f9330ed2af1bdd3a55fd7b624dc9b753df90..646355cd30fc55ea4bd809dff8498dbbb617ef10 100644 (file)
@@ -49,6 +49,11 @@ sub _rest_resources {
             GET => {
                 method => 'parameters'
             }
+        },
+        qr{^/jobqueue_status$}, {
+            GET => {
+                method => 'jobqueue_status'
+            }
         }
     ];
     return $rest_resources;
index 2dd40e0cbda114cb88d736db073782653721a06b..e43472c30b160400463a1c64c8a0d96f42d77df3 100644 (file)
@@ -300,3 +300,32 @@ name             type    description
 ===============  ======  ====================================================
 last_audit_time  string  The maximum of the at_time from the audit_log.
 ===============  ======  ====================================================
+
+Job Queue Status
+----------------
+
+Reports the status of the job queue.
+
+**Request**
+
+.. code-block:: text
+
+   GET /rest/jobqueue_status
+
+This method requires an authenticated user. 
+
+**Response**
+
+.. code-block:: js
+
+   {
+     "total": 12,
+     "errors": 0
+   }
+
+===============  =======  ====================================================
+name             type     description
+===============  =======  ====================================================
+total            integer  The total number of jobs in the job queue.
+errors           integer  The number of errors produced by jobs in the queue.
+===============  =======  ====================================================
\ No newline at end of file
index cf32548b6bed2cdd974b3f4e9767164de8d8e70b..bf1ff5ad37b10fff37b1424c0647a7adac42b9b2 100644 (file)
     to the <code>JOB_MAP</code> constant in <code>Bugzilla::JobQueue</code>,
     perhaps by using the 'job_map' hook.
 
+  [% ELSIF error == "jobqueue_status_error" %]
+    An error occurred while checking the job queue status. Try again at a
+    later time.  
+
   [% ELSIF error == "ldap_bind_failed" %]
     Failed to bind to the LDAP server. The error message was:
     <code>[% errstr FILTER html %]</code>