Releases: ori88c/non-overlapping-recurring-task
Releases · ori88c/non-overlapping-recurring-task
Improve README and documentation explanation of the shouldExecuteFinalRun flag
Add shouldExecuteFinalRun flag for final execution on stop
Key Features ✨
- Optional Final Digest Run 🧹: The optional
shouldExecuteFinalRun
flag allows a final execution to be performed as part of thestop
process. This is especially useful for tasks that accumulate state between executions and need a final flush to persistent storage to avoid leaving unprocessed data. Examples include delayed publishing of batched Kafka messages and upserting accumulated data into a database.
Improved README coding example
Key Features ✨
- Improve README example to use the batched-items-accumulator package.
First Release
Key Features ✨
- Guaranteed Non-Overlapping Executions 🔒: Prevents race conditions (Race Conditions: How Are They Possible in Single-Threaded JavaScript?) and provides precise control over resource usage. Ideal for batch processing tasks that must run exclusively to manage network bandwidth efficiently.
- Graceful and Deterministic Teardown ⏳: When the
stop()
method is invoked during task execution, it resolves only after the execution is complete. This guarantees smooth resource cleanup, making it well-suited for production environments (e.g.,onModuleDestroy()
in NestJS) and maintaining a clean state between unit tests. - Fixed Delay Between Executions 🔁: Functions similarly to JavaScript's built-in
setInterval
, but skips executions if a previous one is still in progress.
- Flexible First Execution Policy 🎚️: The
immediateFirstRun
option lets you control whether execution begins immediately uponstart()
or only after the first interval. Particularly useful when the task is part of an application’s bootstrap phase (e.g.,onModuleInit()
in NestJS). If the bootstrap phase requires the first execution to complete before proceeding (e.g., before accepting HTTP requests), pair this withwaitUntilCurrentExecutionCompletes()
. - Error Handling
⚠️ : If a periodic task throws an error, it is passed to an optional error handler callback, if provided. This component does not perform any logging, as it is designed to be agnostic of user preferences, such as specific loggers or logging styles. A typical_onTaskError
implementation logs errors based on the user's logging strategy. If the periodic task already handles its own errors, this handler can be omitted. - Execution State Metrics 📊: The
status
andisCurrentlyExecuting
getters offer real-time insights into the scheduler's state, helping users make informed decisions, such as awaitingwaitUntilCurrentExecutionCompletes()
when specific operations must not overlap the recurring task. - Comprehensive documentation 📚: Fully documented, enabling IDEs to provide intelligent tooltips for an enhanced development experience.
- Thoroughly Tested 🧪: Backed by extensive unit tests, covering even rare edge cases, to ensure reliability in production.
- Zero Runtime Dependencies 🕊️: Only development dependencies are included.
- ES2020 Compatibility: The project targets ES2020 for modern JavaScript support.
- Full TypeScript Support: Designed for seamless TypeScript integration.