pg-boss icon indicating copy to clipboard operation
pg-boss copied to clipboard

how to get the number of failed jobs?

Open pthieu opened this issue 9 months ago • 3 comments

In the queue section of the docs, it says that we can get the queue size.

However, we can't pass in the state we're looking for, and instead, there is a before field, which will get you the total number of jobs in what looks like a linear list of states.

In the job definition, the states are listed as:

state: 'created' | 'retry' | 'active' | 'completed' | 'cancelled' | 'failed';

This means we can probably make a query for each of the states and do some math to get the number for each state except failed, because there's no state after it to specify in the before field.

Is there a way to get the number of failed jobs or is there another way to get queue numbers?

pthieu avatar Mar 22 '25 17:03 pthieu

You can write your own query against the table if you want. There is also an event monitor-states that could be used, but this may not exist by the time v11 is released

timgit avatar Mar 26 '25 22:03 timgit

@timgit does pgboss expose a method to query the db through its connection? I'm using Drizzle, so I'd either have to hack around their raw query method or generate a schema for pgboss and use that.

pthieu avatar Mar 27 '25 02:03 pthieu

Seems like a good thing to add to the API. It's not there yet.

timgit avatar Mar 27 '25 02:03 timgit

I revisited this and remembered I expose this is already exposed via getDb()

timgit avatar Jul 06 '25 20:07 timgit

Hey @timgit

getDb() is not in types file. I can make a PR for this if you approve this change

stalniy avatar Aug 22 '25 05:08 stalniy

Approved.

timgit avatar Sep 05 '25 15:09 timgit