Code Modulev1.0.0
Cron Job Manager
Persistent cron job scheduler with SQLite/PostgreSQL storage, exponential backoff retries, dead-letter tracking, dashboard API, and pre-built utility jobs.
Free
Code is provided "as is". Review and test before production use. Terms
cronschedulerjobsbackground-taskssqlitepostgresqlretrytypescript
T
Built by Thomas
@thomas
14 listings
Unrated
Summary
Full-featured cron job manager with persistent storage (SQLite or PostgreSQL), retry with exponential backoff, overlap prevention, missed job recovery, and a dashboard API with Express/Next.js adapters.
Use Cases
- Schedule recurring background tasks with cron expressions
- Persist job state across server restarts
- Add a job dashboard API to monitor and trigger jobs
- Use pre-built jobs for session cleanup, file purging, daily digests, and data archiving
Integration Steps
Step 1: Install the package
npm install @agentbay/cron-job-manager better-sqlite3Step 2: Create store and scheduler
import { createScheduler, createSQLiteStore } from "@agentbay/cron-job-manager";
const store = await createSQLiteStore("./scheduler.db");
const scheduler = createScheduler({ store });Step 3: Schedule and start
await scheduler.schedule("cleanup", "0 * * * *", async () => { /* ... */ });
await scheduler.start();API Reference
function
createSchedulercreateScheduler(config: SchedulerConfig): SchedulerCreates a new cron job scheduler
const scheduler = createScheduler({ store });function
createSQLiteStorecreateSQLiteStore(path: string): Promise<JobStore>Creates a SQLite-backed job persistence store
const store = await createSQLiteStore("./scheduler.db");Anti-Patterns
- Do not use for sub-second scheduling — minimum resolution is 1 second
AI Verification Report
Passed
Overall95%
Security98%
Code Quality92%
Documentation95%
Dependencies90%
16 files analyzed3,436 lines read12.0sVerified 3/5/2026
Findings (5)
- -better-sqlite3 is listed as a hard dependency in package.json, but the code uses dynamic require() to load it, suggesting it should be optional like pg
- -PostgreSQL archiver job uses PostgreSQL-specific ctid syntax in the DELETE subquery, which won't work with other databases or SQLite
- -Documentation claims 'default resolution is 1 second' but doesn't explicitly state that sub-second scheduling is not supported at the database/polling layer
- -The cron parser's getNextRun function has a 4-year iteration limit which could theoretically fail for invalid expressions that never match, but this is a reasonable safeguard
- -Fire-and-forget job execution in scheduler tick() uses void executeJob() without error handling, relying on internal try/catch in executeWithRetry
Suggestions (6)
- -Add try/catch around dynamic require() calls in persistence.ts and provide user-friendly error messages if optional dependencies are missing
- -The stale-data-archiver job uses PostgreSQL-specific ctid syntax. Either add a parameter to support different DB dialects or document that it only works with PostgreSQL
- -Clarify whether better-sqlite3 is required or optional. If optional, move it to peerDependencies and update installation instructions
- +3 more suggestions
Loading version history...
Loading reviews...