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

@xtaskjs/scheduler

v1.0.3

Published

Scheduler integration for xtaskjs.

Readme

@xtaskjs/scheduler

Scheduler integration package for xtaskjs.

This package is part of the xtaskjs project, hosted at xtaskjs.io.

Installation

npm install @xtaskjs/scheduler node-cron reflect-metadata

What It Provides

  • Cron-style decorators for declaring scheduled methods on xtaskjs services.
  • Interval and timeout decorators when a fixed delay is simpler than a cron expression.
  • Boot-time execution, named groups, and per-job retry or error hooks.
  • Lifecycle integration so jobs start on ready and stop on app.close().
  • Container tokens and decorators for injecting the scheduler service or lifecycle manager.

Declare Scheduled Jobs

import { Service } from "@xtaskjs/core";
import { Cron, Every, Timeout } from "@xtaskjs/scheduler";

@Service()
class ReportsScheduler {
  @Cron("0 */5 * * * *", {
    name: "reports.flush",
    timeZone: "UTC",
    group: ["reports", "nightly"],
    runOnBoot: true,
    maxRetries: 2,
    retryDelay: "15s",
    onError: "handleFlushError",
  })
  async flushReports() {
    console.log("flush pending reports");
  }

  @Every("10m", { name: "reports.compact" })
  compactCache() {
    console.log("compact cache every ten minutes");
  }

  @Timeout("30s", { name: "reports.warmup" })
  warmup() {
    console.log("run once after startup");
  }

  handleFlushError(error: Error) {
    console.error("report flush failed", error);
  }
}

Inject The Scheduler Service

import { Service } from "@xtaskjs/core";
import { InjectSchedulerService, SchedulerService } from "@xtaskjs/scheduler";

@Service()
class SchedulerInspector {
  constructor(
    @InjectSchedulerService()
    private readonly scheduler: SchedulerService
  ) {}

  printJobs() {
    return this.scheduler.listJobs();
  }

  printReportJobs() {
    return this.scheduler.listJobs("reports");
  }

  async runNow(name: string) {
    await this.scheduler.runJob(name);
  }

  async rerunOpsGroup() {
    await this.scheduler.runGroup("ops");
  }
}

Decorators

  • @Cron(expression, options) registers a cron expression using node-cron.
  • @Every(interval, options) registers a recurring interval. Examples: 5000, "15s", "10m", "1h".
  • @Interval(interval, options) is an alias for @Every.
  • @Timeout(delay, options) runs a method once after startup.

Options

  • name: stable job name. Defaults to ClassName.methodName.
  • disabled: keep the job registered but do not start it automatically.
  • group: assign one or more named groups for bulk operations like runGroup("ops").
  • runOnBoot: run the job once during application bootstrap, before lifecycle ready.
  • runOnInit: run immediately when the scheduler starts, then continue on the normal cadence.
  • allowOverlap: allow a new execution while the previous one is still running.
  • maxRetries: retry a failed execution this many times before surfacing the final error.
  • retryDelay: wait between retries. Examples: 250, "5s", "2m".
  • onRetry: callback or instance method name invoked before each retry.
  • onError: callback or instance method name invoked after the final failed attempt.
  • timeZone: cron timezone override.

Group Operations

SchedulerService supports bulk operations per group.

await scheduler.startGroup("reports");
await scheduler.stopGroup("reports");
await scheduler.runGroup("reports");

const groups = scheduler.listGroups();
const reportJobs = scheduler.listJobs("reports");

Lifecycle Behavior

  • During CreateApplication(): scheduled jobs are discovered after the DI container is ready.
  • Jobs with runOnBoot execute once during integration initialization.
  • On lifecycle ready: recurring and delayed jobs start automatically.
  • During app.close(): all running jobs are stopped before the container is destroyed.

Resources