pg-boss: Jobs are not being executed when there is no activity on a specific queue

So, let’s say that we have some jobs on queue1 and their startAfter property is in the past for all of them. If no other job is scheduled in queue1, then no job on that queue is completed, even though they should be. Does anyone have any idea what’s going on?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 20 (7 by maintainers)

Most upvoted comments

I’d enable query logging in your development env (https://stackoverflow.com/questions/722221/how-to-log-postgresql-queries), replicate the issue and then look for the fetchNextJob (https://github.com/timgit/pg-boss/blob/master/src/plans.js#L195-L215 ) query, see if it’s still running. If it is, you at least have some ground to stand on to look for the issue.

Alternatively, you could try running the query yourself, perhaps the jobs that are hanging are locked for some erroneous reason (I can’t see how it could happen while the rows keep the ‘created’ state, but it’s worth verifying.

      SELECT *
      FROM pgboss.job
      WHERE state < 'active'
        AND startAfter < now()
      ORDER BY priority desc, createdOn, id
      LIMIT 1
      FOR UPDATE SKIP LOCKED

If that returns 0 rows, yet your job table is full of jobs, it’s because they are locked (the for update skip locked is crucial). I suspect this to not be the case, and it’s more likely that the fetchNextJob query isn’t running. But again, worth to check.

How is the server restarted? Any possible special circumstances? Is it possible that boss.start() isn’t called?