fp/services/capture/src/blah.ts

31 lines
719 B
TypeScript
Raw Normal View History

2024-07-28 00:42:09 +00:00
import PgBoss from 'pg-boss';
async function readme() {
const boss = new PgBoss('postgres://william:mysecretpassword@localhost:5435/william');
boss.on('error', (error: Error) => console.error(error));
await boss.start();
const queue = 'some-queue';
let jobId = await boss.send(queue, { param1: 'foo' })
console.log(`created job in queue ${queue}: ${jobId}`);
await boss.work(queue, someAsyncJobHandler);
}
async function someAsyncJobHandler(job: any) {
console.log(`job ${job.id} received with data:`);
console.log(JSON.stringify(job.data));
await new Promise((resolve, reject) => {
console.log('waiting 3s')
setTimeout(() => {
resolve(job.data)
}, 3000)
});
}
readme()