timgit / pg-boss

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

feature-request: It should be possible to predict a job key or id. #419

Closed nuelsoft closed 3 months ago

nuelsoft commented 1 year ago

There are cases where an actor would want to replace an already scheduled job. The current solution doesn't allow for this or any kind of job filtering by data jsonb object.

An example use-case


function schedulePendingActionNotificaion(userId: string) {
  const queue = 'pending-actions-notifcation'
  const key = `pending-action::${userId}`
  boss.cancel({name: queue, key})
  boss.send(queue, {userId}, { key })
}

This doesn't have to replace the existing id, It should only another possible reference that can be predicted uniquely

jorinvo commented 1 year ago

It would be sufficient if pg-boss allows passing an id to send() instead of pg-boss generating a uuid.

Without being able to set IDs ourselves, we currently have to maintain a separate table to map IDs.

timgit commented 1 year ago

This would be a good option to send(). You can use insert([jobs]) for now, however.

jorinvo commented 1 year ago

Thanks @timgit! insert() does what we need. And thank you for the work on this lib :)

nuelsoft commented 1 year ago

Hello @timgit, thank you for the pointer. I was more worried by this https://github.com/timgit/pg-boss/blob/64df1e471fdd44469702467ff09420c7396ba685/src/plans.js#L138

It would be nice to maybe drop the type from uuid to a more flexible string.

Thanks again.

timgit commented 3 months ago

send() now supports an { id } option in v10