npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@azlib/scheduler

v1.2.2

Published

Cron-style job scheduler for Node.js, supporting timezone normalization, overlap prevention policies, missed run executions, and database persistence.

Readme

@azlib/scheduler

Cron-style job scheduler for Node.js, supporting timezone normalization, overlap prevention policies, missed run executions, and database persistence.

Capabilities

  • Schedule parsing and timezone normalization
  • Job registration and lifecycle control (start, stop)
  • Standalone runner execution or embedded hosting (e.g. Express)
  • Host lifecycle bindings for graceful setups
  • Queue-backed execution dispatch through @azlib/queue
  • Cache coordination using @azlib/cache
  • Structured database state persistence (SQL persistence)
  • Operator dashboard (HTTP + React UI) for monitoring and controlling jobs

AI Agent Quick Reference

Core Exports

| Export | Type | Description | | ------------------------------------------------------------------------------- | -------- | -------------------------------------------------------------------------- | | createSchedulerService(options: SchedulerServiceOptions) | Function | Instantiates a SchedulerService instance and a Handler Registry. | | createCronExpression(): CronExpressionBuilder | Function | Fluent helper to construct standard 5-field cron strings. | | bindSchedulerToHost(service: SchedulerService, adapter: SchedulerHostAdapter) | Function | Automatically starts/stops the scheduler based on custom server bindings. | | CronWeekday | Enum | Monday through Sunday utility enum values. | | createSchedulerDashboardService(scheduler, options?) | Function | Operator API: health, list, pause/resume, run-now, retry, CRUD. | | createSchedulerDashboardFromPersistence(persistence) | Function | Sidecar dashboard against the same SQL tables (does not start the engine). | | createSchedulerDashboardServer(options) | Function | Serves the React UI and JSON API (@azlib/scheduler/dashboard). | | createSchedulerDashboardNodeHandler(options) | Function | Same monitor as the standalone server, for Express/http hosts. |

Dashboard

The dashboard can run in-process next to a live SchedulerService, or as a sidecar / Docker process that shares SQL persistence. The sidecar never starts a second scheduler engine. Pause/resume writes enabled on the job row; the worker re-reads that on every tick.

import {
  createSchedulerDashboardServer,
  createSchedulerDashboardService,
  createSchedulerDashboardNodeHandler,
} from "@azlib/scheduler/dashboard";

const dashboard = createSchedulerDashboardService(service, { handlers });
const server = createSchedulerDashboardServer({
  dashboard,
  port: 9100,
  host: "127.0.0.1",
});
await server.listen();

// Or mount the same monitor on an existing Node/Express server:
app.use(
  createSchedulerDashboardNodeHandler({
    dashboard,
    basePath: "/scheduler",
    authorize: async ({ authorization }) => {
      // throw DashboardHttpError(401 | 403, message) to reject
    },
  }),
);

Sidecar CLI (azlib-scheduler-dashboard) and Docker (packages/scheduler/Dockerfile, compose.yaml):

| Env | Default | Notes | | --------------------- | ---------------------------------- | ------------------------------------------------ | | DATABASE_URL | required | Same database as the worker | | SCHEDULER_DIALECT | inferred from URL | postgres (default), mysql, sqlite, mssql | | SCHEDULER_NAMESPACE | azlib | Table prefix (azlib__scheduler_jobs, …) | | HOST | 127.0.0.1 | Use 0.0.0.0 in Docker | | PORT | 9100 | | | DASHBOARD_TOKEN | required when HOST is not loopback | Authorization: Bearer … on /api/* |

Install the matching SQL driver (pg, mysql2, better-sqlite3, or mssql) next to @azlib/scheduler. Run-now and retry enqueue only when the worker’s queue is reachable; pause, resume, update, and delete work from SQL alone.

DASHBOARD_TOKEN=secret docker compose -f packages/scheduler/compose.yaml up --build

Core Types & Signatures

  • SchedulerService:
    • start(): Promise<void>
    • stop(): Promise<void>
    • registerJob(job: SchedulerJobDefinition): Promise<void>
    • unregisterJob(jobName: string): Promise<void>
  • SchedulerHandlerRegistry:
    • register(key: string, handler: (config?: any) => Promise<void>): void
  • SchedulerJobDefinition:
    • name: string
    • handlerKey: string
    • schedule: SchedulerScheduleConfig
    • config?: any (JSON-serializable config injected into handler)
  • SchedulerScheduleConfig:
    • scheduleType: "cron"
    • expression: string
    • timezone?: string (e.g. "UTC", "Asia/Saigon")
    • overlapPolicy: "allow" | "skip" | "enqueue"
    • missedRunPolicy: "run-immediately" | "skip"

Basic Usage

import { createQueueService } from "@azlib/queue";
import { createSchedulerService, createCronExpression } from "@azlib/scheduler";

const queue = createQueueService({/* ... */});

const { service, handlers } = createSchedulerService({
  mode: "standalone",
  queueService: queue,
});

// 1. Register executor logic
handlers.register("purge-logs", async (config: { thresholdDays: number }) => {
  await db.logs.deleteOlderThan(config.thresholdDays);
});

// 2. Register scheduled trigger
await service.registerJob({
  name: "nightly-purge",
  handlerKey: "purge-logs",
  schedule: {
    scheduleType: "cron",
    expression: createCronExpression().dailyAt(2, 30).build(), // 02:30 AM
    timezone: "UTC",
    overlapPolicy: "skip",
    missedRunPolicy: "run-immediately",
  },
  config: { thresholdDays: 30 },
});

// 3. Boot scheduler
await service.start();

Behavioral Gotchas

  • Timezone Safety: Always specify a timezone in job configs to prevent local developer clocks from altering trigger cycles.
  • Overlap Policies:
    • skip: If a previous job execution is still running, the new scheduled trigger is skipped.
    • enqueue: Queues the new run to execute immediately after the active run completes.
    • allow: Runs execution concurrent to existing instances (warning: potential race conditions).
  • Execution Engine: Jobs are not run inside the scheduler thread directly. Instead, they are dispatched as tasks to the configured @azlib/queue provider to preserve single-thread event loop safety.