timgit / pg-boss

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

jobs' UUIDs generated in app not random #342

Closed aefji closed 1 year ago

aefji commented 1 year ago

Thanks for the amazing work.

Generating multiple jobs within the same timestamp or second, seems the uuids are not random at all

created jobs in queue 57ad8dd0-1985-11ed-8a9e-237678a9bd8e, 57b33320-1985-11ed-8a9e-237678a9bd8e, 57b751d0-1985-11ed-8a9e-237678a9bd8e, 57bc5ae0-1985-11ed-8a9e-237678a9bd8e

The issue seems to be with 'uuid' package in manager.js

1) Seems you are generating and sending the uuid in app instead of letting PG do it. Is it for less roundtrips? Or cpu? 2) If you must do it in app, would you consider changing the 'uuid' package to 'crypto'? Changing to crypto.randomUUID() fixes the issue.

timgit commented 1 year ago

This is the default v1 uuid. You can change this to v4 via the uuid configuration if you want

aefji commented 1 year ago

Thanks for the explanation.

Just by looking at the table I would expect a v4 default, as this is what PG would generate. (Builtin crypto would reduce project dependencies.)