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

@argos-js/routine

v0.1.2

Published

Time-oriented periodic routine scheduling with atomic locks and concurrency protection for Argos-JS

Readme

@argos-js/routine

Time-oriented periodic routine scheduling with atomic locks and concurrency protection for the Argos-JS framework.


Features

  • Strict Conceptual Separation: Dedicated exclusively to time-based schedules (periodic maintenance, synchronization, reports, backups).
  • Distributed Concurrency Semantics: Built-in atomic locking via .lock({ ttl: '10m' }) and its direct alias .preventOverlap().
  • Silent Skipping: When a routine is currently running and locked, subsequent executions are discarded silently rather than piling up.
  • Immediate Lock Release: Locks are immediately released in finally blocks upon completion or failure (never waiting for TTL to elapse).
  • Deadlock Protection: If a node or process crashes mid-execution, locks auto-expire after TTL to prevent infinite deadlocks.
  • Zero External Required Dependencies: Works with MemoryLockAdapter (testing/dev) and DatabaseLockAdapter (@argos-js/data transactional locks).
  • Queue Integration: Direct dispatching to @argos-js/queue with .dispatch(job, payload).

Installation

pnpm add @argos-js/routine @argos-js/queue

Quick Start

1. Defining Routines

import { routine } from '@argos-js/routine';
import { cleanupLogsJob } from './jobs/cleanup.job.js';

// 1. Routine with preventOverlap (default 10m TTL)
routine('generate-hourly-metrics')
  .hourly()
  .preventOverlap()
  .run(async (context) => {
    console.log(`[Routine ${context.routineName}] Running metrics compilation for ${context.scheduledTime}`);
    // Compiling metrics...
  });

// 2. Routine running on interval with custom TTL
routine('sync-external-inventory')
  .every('5m')
  .lock({ ttl: '15m' })
  .run(async (context) => {
    // Inventory sync logic...
  });

// 3. Routine running daily at specific time
routine('database-backup')
  .dailyAt('03:00')
  .preventOverlap({ ttl: '1h' })
  .run(async (context) => {
    // Perform automated backup...
  });

// 4. Routine dispatching an asynchronous queue job
routine('daily-disk-cleanup')
  .dailyAt('04:00')
  .dispatch(cleanupLogsJob, { olderThanDays: 30 });

2. Running the Routine Daemon

import { RoutineRunner, DatabaseLockAdapter, LockManager, setDefaultLockManager } from '@argos-js/routine';
import { createDatabase } from '@argos-js/data';

// Optional: Use database-backed locks for multi-instance distributed deployments
const db = createDatabase({
  driver: 'postgres',
  connectionString: process.env.DATABASE_URL,
});

const lockManager = new LockManager(new DatabaseLockAdapter(db));
setDefaultLockManager(lockManager);

const runner = new RoutineRunner({
  resolutionMs: 1000, // 1-second resolution loop
  lockManager,
});

// Setup SIGTERM / SIGINT graceful handling
runner.setupSignalHandlers();

await runner.start();

CLI Management

The official Argos CLI provides semantic commands to control routines:

# Start routine runner daemon
argos routine start

# List all registered routines, schedules, and lock status
argos routine list

# Manually trigger a routine immediately (bypasses schedule, respects locks)
argos routine run generate-hourly-metrics

Unified Daemon

In containers or single-instance setups, run both queue workers and the routine runner in the same unified daemon:

argos daemon start --workers=4

Production Deployment

Systemd Service (/etc/systemd/system/argos-routine.service)

[Unit]
Description=Argos-JS Periodic Routine Runner
After=network.target

[Service]
Type=simple
User=argos
WorkingDirectory=/var/www/my-argos-app
Environment=NODE_ENV=production
ExecStart=/usr/bin/node ./dist/app/index.js --routine
Restart=always
RestartSec=5
KillSignal=SIGTERM
TimeoutStopSec=30

[Install]
WantedBy=multi-user.target

Docker Container (Unified Daemon)

FROM node:20-alpine AS runner
WORKDIR /app

COPY package.json pnpm-lock.yaml ./
RUN npm install -g pnpm && pnpm install --prod

COPY dist ./dist

ENV NODE_ENV=production
STOPSIGNAL SIGTERM

CMD ["node", "./node_modules/@argos-js/cli/bin/argos.js", "daemon", "start", "--workers=4"]