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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@squirrel-scheduler/core

v1.0.7

Published

Core scheduling library for SquirrelScheduler — queue tasks in any DB, then poll & execute them.

Readme

@squirrel-scheduler/core

A lightweight scheduling library for Node.js. @squirrel-scheduler/core lets you queue tasks to be executed in the future, store them in any database, and poll for pending tasks at your own pace.

Features

  • Database-Agnostic: Implement a simple SDBAdapter interface for your preferred DB (MySQL, PostgreSQL, MongoDB, etc.)
  • Pluggable: Already includes a DrizzleAdapter for SQLite databases
  • Retry Logic: Handle transient failures by incrementing retryCount and rescheduling tasks if needed
  • Simple Polling: Call .sync() on your own schedule (e.g., via setInterval, cron, or an external trigger)

Installation

npm install @squirrel-scheduler/core

Or with pnpm:

pnpm add @squirrel-scheduler/core

Quick Usage Example

import { SScheduler } from "@squirrel-scheduler/core";

// Import your custom DB adapter that implements SDBAdapter
// e.g., the Drizzle Adapter:
import { SQLiteDrizzleAdapter } from "@squirrel-scheduler/drizzle-adapter";

// Suppose we have a drizzle-orm instance configured for SQLite
import { drizzle } from "drizzle-orm/libsql";
import { createClient } from "@libsql/client";

const client = createClient({
  url: process.env.TURSO_DB_URL, 
  authToken: process.env.TURSO_DB_TOKEN
});
const db = drizzle(client);

(async () => {
  // 1. Create an adapter
  const dbAdapter = SQLiteDrizzleAdapter(db);

  // 2. Create a scheduler instance
  const scheduler = new SScheduler(dbAdapter);

  // 3. Add tasks
  scheduler
    .add({
      payload: { event: "sendEmail", to: "[email protected]" },
      scheduledAt: new Date(Date.now() + 5000), // 5 seconds in the future
    })
    .add({
      payload: { event: "generateReport", reportId: "abc123" },
      scheduledAt: new Date(Date.now() + 15000), // 15 seconds in the future
    });

  // 4. Persist tasks in the DB
  await scheduler.schedule();

  // 5. Later or periodically, call sync() to claim & execute due tasks
  await scheduler.sync();
})();

Conceptual Overview

Add Tasks

You enqueue tasks by calling .add() on the SScheduler instance, specifying a payload and a scheduledAt timestamp.

Store Tasks

Invoke .schedule() to persist them in your database via the adapter.

Sync & Execute

Periodically (or on-demand), call .sync():

  1. Fetches pending tasks that are due (scheduledAt <= now)
  2. Claims them (sets status = in_progress)
  3. Executes each task (the default example logs or simulates your action)
  4. On success, updates status to completed. On failure, increments retryCount and reschedules or fails based on maxRetries

SDBAdapter

The SDBAdapter interface defines how to store, update, and fetch tasks. This core package is database-agnostic. If you need a ready-made solution for SQLite with Drizzle ORM, check out @squirrel-scheduler/drizzle-adapter.

SDBAdapter Interface

Implement these methods to integrate with any DB:

export interface SDBAdapter {
  createTask(data: Omit<STask, "id" | "status" | "retryCount" | "createdAt" | "updatedAt">): Promise<STask>;
  createTasks(data: Array<Omit<STask, "id" | "status" | "retryCount" | "createdAt" | "updatedAt">>): Promise<STask[]>;
  getTask(id: string): Promise<STask | null>;
  listTasks(params: ListTasksParams): Promise<STask[]>;
  updateTask(taskId: string, update: Partial<Omit<STask, "id">>): Promise<STask>;
  claimTasks(tasks: STask[]): Promise<STask[]>;
  setLastSync(at?: Date, args?: { totalTasks: number }): Promise<void>;
  recordTaskAttempt(taskId: string, result: TaskAttemptResult): Promise<void>;
  pruneTasks(params: PruneTasksParams): Promise<number>;
  getLastSync(): Promise<{ timestamp: number | Date; totalTasks: number }>;
}

Implementing these methods for your DB of choice allows SquirrelScheduler to store and update tasks seamlessly.

Roadmap

  • Official Adapters for MySQL, PostgreSQL, MongoDB, etc.
  • Concurrency: Parallel execution of tasks (optional)
  • Retry Strategies: Exponential backoff, custom scheduling for failed tasks
  • UI / Dashboard: Possibly track scheduled tasks visually

Contributing

We love contributions! Feel free to open PRs for new adapters, additional features, or bug fixes. See CONTRIBUTING.md (if you have one) for guidelines.

License

MIT

Happy Scheduling! If you have questions or feedback, open an issue on GitHub.