Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should expire_in_seconds set the state to expired? #443

Open
Eomm opened this issue Apr 23, 2024 · 1 comment
Open

Should expire_in_seconds set the state to expired? #443

Eomm opened this issue Apr 23, 2024 · 1 comment

Comments

@Eomm
Copy link

Eomm commented Apr 23, 2024

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

pg-boss/src/manager.js

Lines 225 to 227 in f1c1636

await resolveWithinSeconds(Promise.all([callback(jobs)]), maxExpiration)
.then(() => this.complete(jobs.map(job => job.id)))
.catch(err => this.fail(jobs.map(job => job.id), err))

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();
  });
}
@timgit
Copy link
Owner

timgit commented Jul 13, 2024

The expired state will be obsolete in v10 to make this more consistent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants