timgit / pg-boss

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

No tables are created when testing out and no events seems to be subscribed #350

Closed jianinz closed 1 year ago

jianinz commented 1 year ago

Hi everyone, I am a newbie into using pg-boss. Trying to use this library to schedule a job. I did a simple setup like in README instructed. But I don't see any table is created in the empty pgboss database. Wondering that did I miss anything?

Also when I substituted

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

with

 await boss.start();
 await boss.schedule(
    "task-name",
    "* * * * *",
    { param1: 'foo' },
  );

await boss.subscribe("task-name", someAsyncJobHandler);

I don't see any job being scheduled neither subscribed, whereas if using boss.work() would trigger someAsyncJobHandler, any guidance of what I missed would be really appreciated!

timgit commented 1 year ago

Welcome! The tables are stored in a schema named pgboss. You're probably looking for the tables in the public schema. In the latter example, you should be using work and not subscribe if you want that callback to run every minute like you have in your cron.

jianinz commented 1 year ago

Thanks @timgit! I now found the tables in the pgboss schema. Although I don't quite get why using subscribe function won't execute the callback in the above example?

I changed the code to the following just for testing purpose, but no console log when subscription happens

await boss.schedule('analytics', `* * * * *`);
await boss.subscribe('analytics', async (job) => {
    console.log(`Subscription is running: ${new Date().toString()}`);
    job.done();
});

Any ideas?

jianinz commented 1 year ago

Think I might understand why the async function was not invoked, It is just the name of the queue according to the doc

In my use case, I would subscribe the queue on the app start, then manually publish data to the queue, then based on the cron job defined, it executed the async function