Task scheduling on Redis for AntelopeJS. Schedule a task for a given time and the application runs it when due, with up to three retries.
Documentation · Implementations · All interfaces and providers
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.
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.
| Module | Notes |
|---|---|
@antelopejs/redis |
Also implements @antelopejs/interface-redis, which supplies the Redis client the scheduler uses |
Add the interface to the module that schedules tasks:
pnpm add @antelopejs/interface-redis-schedulerThen add the implementation to the project:
ajs project modules add @antelopejs/redisimport { 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.
The module declares these peer dependencies:
| Package | Supported | Tested with |
|---|---|---|
@antelopejs/interface-core |
>=0.5.1 <0.6.0 |
0.5.1 |
@antelopejs/interface-redis |
>=0.0.10 <0.1.0 |
0.0.10 |
Read CONTRIBUTING.md before you open a pull request. The local checks are:
pnpm install
pnpm lint
pnpm testThis package belongs to AntelopeJS, the TypeScript framework where modules depend on contracts and the application chooses the provider. The open-source back office AntelopeJS DMS is built on it.
| Area | Contracts | Providers |
|---|---|---|
| API | interface-api · interface-api-util · interface-data-api |
api |
| Auth | interface-auth |
auth-jwt |
| Database | interface-database · interface-database-decorators · interface-database-catalog · interface-mongodb · interface-rethinkdb |
postgres · mysql · mongodb · rethinkdb |
| Redis | interface-redis · interface-redis-scheduler |
redis |
interface-email |
nodemailer · brevo |
|
| File storage | interface-file-storage |
file-storage-local · file-storage-s3 |
| Payments | interface-payment · interface-subscriptions · interface-stripe |
stripe · mollie · checkout-com · payment-subscriptions |