Create an endpoint that will report back the number of jobs currently in the jobqueue

RESOLVED FIXED

Status

()

enhancement
RESOLVED FIXED
a year ago
a year ago

People

(Reporter: ckolos, Assigned: imadueme, Mentored)

Tracking

Production

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

45 bytes, text/x-github-pull-request
dylan
: review+
Details | Review
(Reporter)

Description

a year ago
if possible, please make it possible to query a REST endpoint to return the number of jobs currently waiting in the queue for monitoring purposes.
I would imagine the result of the API method would look something like:

{
  "waiting":12,
  "deferred":0,
  "errors":5
}

where the sum of the three is the total jobqueue current entries. I am not even sure we would need authentication for the method as it doesn't really give out anything sensitive. Unless maybe someone is trying to DoS BMO and they want to see how high the numbers go. We could wrap a group access around it or just require caller to be logged in. 

imadueme, would you want to take a look at this?

dkl
(Assignee)

Comment 2

a year ago
Hey dkl, I would be happy to look into adding this. I will need some guidance on how to get started or a reference to exisiting code that is similar. Thanks.
(In reply to Israel Madueme [:imadueme] from comment #2)
> Hey dkl, I would be happy to look into adding this. I will need some
> guidance on how to get started or a reference to exisiting code that is
> similar. Thanks.

bug 1204683 is a good reference on how to add a REST API endpoint to the different files involved.

Instead of returning user data, you will need to query the DB directly to get the different counts from the jobqueue. And then return a hash containing the count values.

# UNTESTED
sub jobqueue_status {
    my ( $self, $params ) = @_;

    Bugzilla->login(LOGIN_REQUIRED);

    my $query = "
        SELECT
            COUNT(*) AS total
            (SELECT COUNT(*)
               FROM ts_error
              WHERE ts_error.jobid = j.jobid
            ) AS errors,
        FROM
            ts_job j
            INNER JOIN ts_funcmap f
                ON f.funcid = j.funcid";

    return $dbh->selectall_arrayref($query, { Slice => {} });   
}
Mentor: dkl
(Assignee)

Updated

a year ago
Assignee: nobody → imadueme
Status: NEW → ASSIGNED
(Assignee)

Comment 4

a year ago
Posted file Github PR #514
(Assignee)

Comment 5

a year ago
The endpoint will be at /rest/jobqueue_status next deploy.
@dkl: This only includes the 'total' and 'errors' fields; do you still think the 'deferred' field is needed? If so can you point me to the relevant SQL tables that that information can be pulled from? Thanks.
Flags: needinfo?(dkl)
(In reply to Israel Madueme [:imadueme] from comment #5)
> The endpoint will be at /rest/jobqueue_status next deploy.
> @dkl: This only includes the 'total' and 'errors' fields; do you still think
> the 'deferred' field is needed? If so can you point me to the relevant SQL
> tables that that information can be pulled from? Thanks.

Thinking about this more, the entry only stays in the deferred state for a very short period. For monitoring, we are only really interested in total and number of errors so leave out deferred.

dkl
Flags: needinfo?(dkl)
(Assignee)

Updated

a year ago
Status: ASSIGNED → RESOLVED
Last Resolved: a year ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.