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

Should expire_in_seconds set the state to expired?

Open Eomm opened this issue 1 year ago • 0 comments

I was wondering if the expire_in_seconds should set a job's state to expired instead of error here:

https://github.com/timgit/pg-boss/blob/f1c1636caf9518ec9cd3fe0d0e2844ee98179e68/src/manager.js#L225-L227

I was able to get an exipired state only when the job is active and I stop and restart pg-boss. Is this expected?

Example:

'use strict';

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

buildConsumer();

async function buildConsumer () {
  const boss = new PgBoss({
    user: 'postgres',
    password: 'postgres',
    schema: 'postgres',
  });

  await boss.start();

  const jobId = await boss.send('queueName', { body: 'foo' }, { expireInSeconds: 2 });
  console.log('📣 Inserted job');

  await boss.work(
    'queueName',
    {
      teamSize: 1,
      newJobCheckInterval: 100,
    },
    async () => {
      console.log('🐌 Started SLOW job');
      await new Promise((resolve) => setTimeout(resolve, 5_000));
      console.log('Done job');

      const job = await boss.getJobById(jobId);
      console.log({ job }); // ❗️ state: 'failed', message: 'handler execution exceeded 2000ms'
    },
  );
  console.log('📣 Start worker');

  process.on('SIGINT', async () => {
    console.log('📣 Stopping');
    await boss.stop();
    console.log('📣 Stopped');
    process.exit();
  });
}

Eomm avatar Apr 23 '24 11:04 Eomm