Skip to content

About

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.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

 

History

83 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

INTERFACE · REDIS SCHEDULER: part of AntelopeJS, hexagonal architecture beyond your own code. A glowing button reads Star AntelopeJS.

@antelopejs/interface-redis-scheduler

npm License Discord Documentation Star AntelopeJS

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.

What it offers

  • setHandler registers the function that runs one kind of task.
  • addTask schedules a task for a Unix timestamp in milliseconds. removeTask removes the queued entry before it runs.
  • enableListener starts task processing. disableListener closes 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.5.1 <0.6.0 0.5.1
@antelopejs/interface-redis >=0.0.10 <0.1.0 0.0.10

Contributing

Read CONTRIBUTING.md before you open a pull request. The local checks are:

pnpm install
pnpm lint
pnpm test

Part of AntelopeJS

This 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
Email 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

License

Apache-2.0

About

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.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages