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

@arikajs/scheduler

v0.10.7

Published

Task scheduling for ArikaJS.

Readme

Arika Scheduler

@arikajs/scheduler provides a clean, expressive, and framework-integrated task scheduling system for the ArikaJS ecosystem.

It allows you to define scheduled jobs directly in code using a fluent API — designed for elegance and clarity — while remaining lightweight and Node.js-native.

The scheduler is designed to work seamlessly with @arikajs/foundation, @arikajs/queue, and @arikajs/logging.


✨ Features

  • 🕒 Fluent scheduling API: Expressive and readable schedule definitions
  • ⚡ Parallel Execution: Non-blocking task execution for high performance
  • 🏆 Cluster Safety: Leader election prevents double-execution in distributed environments
  • 🔁 Cron-based scheduling: Full support for standard cron expressions
  • ⏱ Human-readable intervals: Preset methods like everyMinute(), hourly(), daily()
  • 🧵 Queue integration: Dispatch jobs directly to the background instead of blocking
  • 🪵 Logging integration: Automatically logs task starts, completions, and failures
  • 🛡️ Task Control: Built-in support for timeouts and automatic retries
  • 📡 Lifecycle Events: Real-time monitoring via @arikajs/events
  • 🌍 Timezone support: Run tasks relative to your preferred global or local timezone
  • 🛑 Graceful Shutdown: Safe worker termination without dropping tasks
  • 🟦 TypeScript-first: Full type safety for all scheduling operations

📦 Installation

npm install @arikajs/scheduler

Requires:

  • @arikajs/foundation
  • @arikajs/logging
  • @arikajs/cache (recommended for overlapping & cluster locks)
  • @arikajs/events (optional, for monitoring)

🚀 Quick Start

1️⃣ Define Scheduled Tasks

Create a scheduler definition file (e.g., app/Console/Kernel.ts):

import { Schedule } from '@arikajs/scheduler';

export default (schedule: Schedule) => {
  // Run a closure every minute with a name
  schedule.call(() => {
    console.log('Running every minute');
  }).everyMinute().name('important-sync');

  // Run a CLI command daily with timeout and retries
  schedule.command('app:cleanup')
    .daily()
    .timeout(60) // 1 minute timeout
    .retry(3, 10); // retry 3 times with 10s delay

  // Dispatch a job to the queue hourly
  schedule.job(CleanupJob).hourly();
};

2️⃣ Run the Scheduler

You can run the scheduler in two modes:

Long-running Daemon (Recommended for Production)

arika schedule:work

Single Run (For Cron Jobs)

* * * * * cd /path-to-your-project && node artisan schedule:run >> /dev/null 2>&1

📅 Defining Tasks

🔁 Run a Closure

schedule.call(async () => {
  await db.table('users').where('active', false).delete();
}).everyMinute();

🧾 Run a Command

schedule.command('cache:clear').dailyAt('02:00');

🛡 Advanced Usage

Parallel Execution & Leader Election

The scheduler automatically runs all due tasks in parallel so complex tasks don't block simple ones.

In a clustered environment (multiple servers/containers), the scheduler uses @arikajs/cache to perform Leader Election. Only one server will process the schedule for any given minute, ensuring safety without extra configuration.

Preventing Overlaps

If a specific task should not start if its previous instance is still active:

schedule
  .command('report:generate')
  .everyMinute()
  .withoutOverlapping();

Timezone & Retries

schedule
  .command('backup:run')
  .dailyAt('01:00')
  .timezone('Asia/Kolkata')
  .retry(3, 30); // Retry 3 times with 30s delay between attempts

Monitoring via Events

The scheduler emits events that you can listen to in your EventsServiceProvider:

  • scheduler.TaskStarting
  • `scheduler.TaskFinished
  • scheduler.TaskFailed
Event.listen('scheduler.TaskFailed', (data) => {
    Log.error(`CRITICAL: Task ${data.task} failed! Error: ${data.err.message}`);
});

🏗 Architecture

scheduler/
├── src/
│   ├── Contracts
│   │   └── Task.ts
│   ├── Mutex
│   ├── Event.ts
│   ├── index.ts
│   ├── Schedule.ts
│   ├── Scheduler.ts
│   └── Worker.ts
├── tests/
├── package.json
├── tsconfig.json
└── README.md

📄 License

@arikajs/scheduler is open-source software licensed under the MIT License.


🧭 Philosophy

"If it must run, it must run reliably."