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

Stopping pg-boss gracefully does not wait until stop timeouts #421

Open
StarpTech opened this issue Aug 27, 2023 · 9 comments
Open

Stopping pg-boss gracefully does not wait until stop timeouts #421

StarpTech opened this issue Aug 27, 2023 · 9 comments

Comments

@StarpTech
Copy link

StarpTech commented Aug 27, 2023

Hi, it looks like pg-boss does not respect graceful nor timeout property. I have a simple worker that needs at least 5 seconds to finish. On SIGTERM I clean up all my server resources but boss.stop does not block until the max timeout of 30s is over.

await fastify.pgboss.send(queue, { some: 'data' });

await fastify.pgboss.work(queue, async function someAsyncJobHandler(job) {
  console.log(`job ${job.id} received with data:`);

  // promise wait
  await new Promise((resolve) => setTimeout(resolve, 5000));

  console.log(job);
});

 const stopOptions: PgBoss.StopOptions = {
     timeout: 30_000,
     graceful: true,
	 destroy: false
};
await boss.stop(stopOptions);
@StarpTech StarpTech changed the title Stopping pg-boss graceful does not wait until jobs timeout Stopping pg-boss gracefully does not wait until stop timeouts Aug 27, 2023
@StarpTech
Copy link
Author

My fault. I still had a timeout in the shutdown phase. The bug is still valid.

@StarpTech StarpTech reopened this Aug 27, 2023
@StarpTech
Copy link
Author

StarpTech commented Aug 27, 2023

I was able to workaround this by

await boss.stop(stopOptions);

await new Promise((resolve) => {
  boss.once('stopped', () => resolve(null));
});

fastify.log.info('PgBoss shutdown complete');

I think it would be more intuitive if this is the default behavior of stop(). Would you accept a PR?

@timgit
Copy link
Owner

timgit commented Aug 30, 2023

PRs are always welcome. I think it should be opt-in via as a new option on stop(). Thanks!

@StarpTech
Copy link
Author

StarpTech commented Aug 30, 2023

What's the reason for passing it onto the next cycle here? + why is a delay of 1000ms required?

@StarpTech
Copy link
Author

@timgit friendly ping.

@timgit
Copy link
Owner

timgit commented Sep 6, 2023

Hold off on the PR. v10 will include this

@StarpTech
Copy link
Author

@timgit thank you. Any eta?

@timgit
Copy link
Owner

timgit commented Sep 6, 2023

Interested in the beta?

@StarpTech
Copy link
Author

Sure

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