timgit / pg-boss

Queueing jobs in Postgres from Node.js like a boss
MIT License
2.15k stars 160 forks source link

Issues with queue in v10 #463

Closed stefanvanherwijnen closed 3 months ago

stefanvanherwijnen commented 3 months ago

Hi,

I noticed a few issues while trying to migrate to v10.

import PgBoss from "pg-boss";

const boss = new PgBoss('postgres://user:pass@host/database');

boss.on("error", console.error);

await boss.start();

const queue = "readme-queue";

console.log(await boss.getQueueSize(queue));
if (!(await boss.getQueueSize(queue))) {
  await boss.createQueue(queue);
}
const id = await boss.send(queue, { arg1: "read me" });
await boss.schedule(queue + ":test", "* * * * *", { data: "data" });
console.log(`created job ${id} in queue ${queue}`);

await boss.work(queue + ":*", async (job) => {
  console.log(`received job ${job.id} with data ${JSON.stringify(job.data)}`);
});

Firstly, createQueue() does not seem to be optional and not creating a queue before sending a job to it result in no running jobs at all.

Secondly, using a wildcard in a worker does not seem to work at all (the worker never runs).

Third, running deleteQueue(queue) doesn´t seem to delete the created table and will result in an error when createQueue(queue) is ran after it (error: relation "job_1cf8f2ada856014a7b8b7f085da16cd67a05144a5830a720f1a98755" already exists).

timgit commented 3 months ago

Creating queues is required starting in v10. Wildcards are also currently not supported. These changes are listed in the beta release notes.

stefanvanherwijnen commented 3 months ago

Thanks. I know creating queues is required in v10, but the createQueue documentation states it is an optional step so I was confused. I also couldn't find anything about the wildcard support in the release notes.

I'll keep this open until v10 is released in case anyone else runs into the same problem.

OyugoObonyo commented 1 month ago

@stefanvanherwijnen did you figure out how to delete the queue and its created table?

stefanvanherwijnen commented 1 month ago

@stefanvanherwijnen did you figure out how to delete the queue and its created table?

No, but on startup I check if a queue already exists before creating it. Deleting a queue shouldn't be necessary.

OyugoObonyo commented 1 month ago

By on startup, do you mean when starting your application or is it a check every time you want to interact with a queue?

stefanvanherwijnen commented 1 month ago

When I start the app. If you try to recreate an existing queue it will throw an error.