Closed djvs closed 2 years ago
Try using send()
to create a job and work()
to poll for jobs and run the callback function like in the readme. Pub/Sub is a composition pattern when you want to have 2 queues run from a single event.
That's what I mean - I want every listening worker to process the event.
It's apparent that publish and subscribe are probably the wrong choice here - is there a sane architecture to do this with pg-boss though?
Appears not to be the case and like I should be using pg-pubsub or equivalent for this use case, and pg-boss for conventional jobs.
The architecture of pg-boss is similar to services like AWS SQS and less similar to services like SNS. Pub/Sub was added to pg-boss as a fan-out enhancement to create jobs in queues. While you could decrease the polling interval for your workers to 100ms, it's not designed for low latency.
I've kind of lost track of the API at this point and it's not obvious to me from the docs how to do a fan-out with something of a guarantee that anyone subscribed to "foobar" will get every message published to "foobar". My shotgun approach attempt below:
Running this locally, maybe 1/3 of the time it will publish a message but not run the callback.