Add addScript
, addBulkScript
, and Related Functions for existing Lua Script Atomic Integration
#2980
Labels
enhancement
New feature or request
Description:
I would like to propose a feature that enhances BullMQ's integration with Redis Lua scripting. Specifically, it would be extremely beneficial if the Queue class exposed methods such as addScript, addBulkScript, and other variants of existing queue functions (e.g., pauseScript, resumeScript, etc.) that return the Lua script strings used internally by BullMQ.
Motivation:
There are scenarios where atomicity is crucial, such as when custom Redis operations need to be performed alongside job queuing. While Lua scripting in Redis is a powerful tool for atomic operations, it is currently challenging to enqueue jobs as part of a custom Lua script because:
This feature would enable developers to safely enqueue jobs as part of larger, atomic Lua scripts without needing to understand or replicate BullMQ's internals.
Proposed Solution:
Introduce methods to the Queue class (or relevant classes) that generate and return the Lua script string for existing functions, such as:
addScript(jobName: string, data: object, options: JobOptions): string
addBulkScript(jobs: Array<{ name: string; data: object; options?: JobOptions }>): string
pauseScript(): string
resumeScript(): string
...Script(): string
These methods would return the Lua script string that BullMQ uses internally for the corresponding operations. Developers could then inject these script strings into their existing Lua scripts, ensuring atomicity without sacrificing maintainability.
Example Usage:
Benefits:
Backward Compatibility:
This feature is non-breaking as it introduces new methods without altering existing behavior.
Alternatives:
The current alternative is to manually replicate BullMQ's internal logic for job queuing in custom Lua scripts, which is error-prone and fragile.
Closing Thoughts:
This feature would greatly enhance BullMQ's usability for developers who rely on Redis Lua scripting for atomic operations. I hope the team considers this addition as it aligns well with BullMQ's mission of providing robust and flexible job queueing capabilities.
Thank you for your consideration!
The text was updated successfully, but these errors were encountered: