timgit / pg-boss

Queueing jobs in Node.js using PostgreSQL like a boss
MIT License
1.73k stars 144 forks source link

Multiple start call #404

Closed Eomm closed 1 year ago

Eomm commented 1 year ago

Hello, I was implementing a retry logic during the startup phase of my application.

I noticed that calling the start() method twice while the DB server is turned off, I get a valid result.

This snippet produces this output:

node demo.js
{ err1: 'connect ECONNREFUSED 127.0.0.1:5432' }
{ start2: 'object' }
Started
const PgBoss = require('pg-boss');

(async function () {
  try {
    await buildProducer();
  } catch (error) {
    console.log({ globalErr: error.message });
  }
})();

async function buildProducer() {
  const boss = new PgBoss({
    user: 'postgres',
    password: 'pwd',
    noScheduling: true,
  });

  boss.on('error', (error) => {
    console.log({ onError: error.message }); // doesn't show as expected
  });

  try {
    const start1 = await boss.start();
    console.log({ start1 });
  } catch (error) {
    console.log({ err1: error.message });
  }

  try {
    const start2 = await boss.start();
    console.log({ start2: typeof start2 });
  } catch (error) {
    console.log({ err2: error.message });
  }

  console.log('Started');
}

Is this expected?

timgit commented 1 year ago

That's not expected