timgit / pg-boss

Queueing jobs in Postgres from Node.js like a boss
MIT License
2.07k stars 157 forks source link

`wip` events are not emitted #335

Closed snehesht closed 2 years ago

snehesht commented 2 years ago

I'm building a dashboard for pg-boss pgboss-ui [WIP].

I'm trying to listen on wip events to get the worker state but the wip events are not being emitted.

I'm getting monitor-state events but not wip events, based on the docs they should be emitted every 2 secs when there are active jobs or am I missing something ?

// This doesn't have any queues running on it, it's purely for collecting stats
// await queue.start() is triggered during startup in a different place

import PgBoss = require('pg-boss');

import { environment } from './environments/environment';

const queue: PgBoss = new PgBoss({
  connectionString: environment.pgboss_database_url,
  monitorStateIntervalSeconds: 5,
});

queue.on('error', (error) => {
  console.error(`Queue Error`, error);
});

queue.on('wip', (data: PgBoss.Worker[]) => {
  console.log('WIP', data);
  // process WIP event data
});

This is a great package, I've been using it on my side projects for a while. Thank you :+1:

timgit commented 2 years ago

Events are only raised within the instance that has the worker that fetched the job. A purely monitored instance won't receive them.