timgit / pg-boss

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

WorkHandler type - promise was removed #390

Closed joaoreberti closed 1 year ago

joaoreberti commented 1 year ago

Summary

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 commented 1 year ago

This should be resolved in 9.0.1

joaoreberti commented 1 year ago

The new release fixed the issue 🙏