timgit / pg-boss

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

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

Open nuelsoft opened 10 months ago

nuelsoft commented 10 months 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 10 months 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 10 months ago

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

jorinvo commented 10 months ago

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

nuelsoft commented 10 months 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.