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

WorkHandler type - promise was removed #390

Closed
joaoreberti opened this issue May 5, 2023 · 2 comments
Closed

WorkHandler type - promise was removed #390

joaoreberti opened this issue May 5, 2023 · 2 comments

Comments

@joaoreberti
Copy link

joaoreberti commented May 5, 2023

Summary

  • On drop job.done commit, the type definitions was changed
  • With that change I'm no longer able to use async handlers without using an ignore rule due to @typescript-eslint/no-misused-promises rule
  • Since the example in the readme file has an async handler I assume this was an oversight of some sorts.
  • But perhaps I'm missing something

thanks in advance, great library by the way 🚀

import PgBoss from 'pg-boss';

async function doSomethingAsyncWithThis(data: any): Promise<void> {
  // Implement your function here
  await new Promise((resolve) => {
    resolve(data);
  });
}

async function someAsyncJobHandler(job: PgBoss.Job<any>): Promise<void> {
  console.log(`job ${job.id} received with data:`);
  console.log(JSON.stringify(job.data));

  await doSomethingAsyncWithThis(job.data);
}

async function readme(): Promise<void> {
  const boss: PgBoss = new PgBoss('postgres://user:pass@host/database');

  boss.on('error', (error: Error) => console.error(error));

  await boss.start();

  const queue: string = 'some-queue';

  const jobId = await boss.send(queue, { param1: 'foo' });

  console.log(`created job in queue ${queue}: ${jobId}`);

  await boss.work(queue, someAsyncJobHandler);
}

readme();
@timgit
Copy link
Owner

timgit commented May 10, 2023

This should be resolved in 9.0.1

@joaoreberti
Copy link
Author

The new release fixed the issue 🙏

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