generateId
Generate a random unique ID for jobs.crypto.randomUUID() to create a unique identifier.
Usage
When to Use
UsegenerateId() when you want the queue to handle each enqueue as a separate job, even if the payload is identical.
contentId
Generate a content-based ID by hashing the payload. Useful for deduplication based on content rather than explicit IDs.Usage
When to Use
UsecontentId() for automatic content-based deduplication. Jobs with identical payloads will get the same ID, preventing duplicate processing.
The hash is deterministic: the same payload always produces the same ID. However, key order matters in objects:
{a: 1, b: 2}produces a different hash than{b: 2, a: 1}
Comparison
| Function | Use Case | Deduplication |
|---|---|---|
generateId() | Always process each enqueue as a new job | No - each call gets unique ID |
contentId() | Deduplicate based on payload content | Yes - identical payloads get same ID |
| Custom IDs | Business logic-driven (e.g., user ID + action) | Controlled by your ID scheme |
Complete Example
Implementation Details
Fromsrc/utils/id.ts:6:
See Also
- Deduplication - How job IDs prevent duplicate processing
- Queue API - Using IDs with enqueue methods