@antelopejs/interface-redis-scheduler
Task scheduling on Redis for AntelopeJS. You schedule a task for a given time, and a listener in your application runs it when it is due, with up to three retries on failure.
What it offers
setHandlerregisters the function that runs one kind of task.addTaskschedules a task for a Unix timestamp in milliseconds.removeTaskremoves the queued entry before it runs.enableListenerstarts task processing.disableListenercloses only the notification subscriber, not the pending timer.- Tasks live in a Redis sorted set, so they survive application restarts and every instance of the application sees the same queue. Each due task goes to one listener.
Implementations
| Module | Notes |
|---|---|
@antelopejs/redis | Also implements @antelopejs/interface-redis, which supplies the Redis client the scheduler uses |
Install
Add the interface to the module that schedules tasks:
pnpm add @antelopejs/interface-redis-scheduler
Then add the implementation to the project:
ajs project modules add @antelopejs/redis
Quick start
import { Logging } from "@antelopejs/interface-core/logging";
import {
addTask,
disableListener,
enableListener,
setHandler,
} from "@antelopejs/interface-redis-scheduler";
const ONE_HOUR_MS = 60 * 60 * 1000;
setHandler("overdue-notice", async (taskInfo) => {
const { memberId } = JSON.parse(taskInfo);
Logging.Info(`Remind member ${memberId}`);
});
export async function start() {
await enableListener();
await addTask(
"overdue-notice",
Date.now() + ONE_HOUR_MS,
JSON.stringify({ memberId: "M-1042" }),
);
}
export async function stop() {
await disableListener();
}
Register a handler before you schedule tasks for it. addTask rejects for a handler name that this process has not registered.
disableListener() is not a full shutdown or pause. A pending timer and running handlers can continue to process tasks. Read the lifecycle and delivery limits before you use it for shutdown.
Documentation
Compatibility
The module declares these peer dependencies:
| Package | Supported | Tested with |
|---|---|---|
@antelopejs/interface-core | >=0.2.4 <1.0.0 | 0.2.4 |
@antelopejs/interface-redis | >=0.0.9 <1.0.0 | 0.0.9 |
Contributing
Read CONTRIBUTING.md before you open a pull request. The local checks are:
pnpm install
pnpm lint
pnpm test