timgit / pg-boss

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

How does the `priority` field work? #481

Closed aryamannaik closed 2 months ago

aryamannaik commented 2 months ago

I'd love to know more about how the priority field on send works [link].

  1. Let's say I send job A with pri=2 and job B with pri=1 to their individual queues (queueA, queueB).
  2. Each of these queues have a worker initialized for them through two .work calls on a single process both with priority=true.
  3. Can I make any assumptions regarding the order in which these jobs will run?

Thanks!

timgit commented 2 months ago

Priorities are per-queue, not across queues

aryamannaik commented 2 months ago

Thanks @timgit. Are there any assumptions I can make about priority across queues? Let's say I have one queue that processes very high priority jobs (important-queue), another that does not (not-important-queue). I don't want slow jobs on not-important-queue to hog resources and starve processing of the important-queue. Is there a mechanism to address this use case?

timgit commented 2 months ago

I'm not sure I understand what you mean by "resources", but each call to work() creates an independent polling loop for that queue, so they don't wait on each other.

aryamannaik commented 2 months ago

My worry is that a job on not-important-queue starves memory or CPU on the machine (these are the resources I'm referring to) from important-queue. Ideally, I'd want some way to mark one queue as more important than the others to avoid this from happening.

timgit commented 2 months ago

Your concern seems very specific to your use case. The simplest solution in this architecture seems to be to run each worker on an isolated machine.

aryamannaik commented 2 months ago

Gotcha, thanks @timgit!