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

@quarry-systems/drift-timer

v0.1.0-alpha.1

Published

Timer and scheduling plugin for Drift

Downloads

211

Readme

MCG Timer Plugin

A comprehensive timer and scheduling plugin for Managed Cyclic Graph (MCG) that enables nodes to delay execution, wait for specific times, and schedule based on cron-like patterns.

Features

  • Simple Delays: Sleep for a specified duration
  • Scheduled Waits: Wait until a specific date/time
  • Cron Patterns: Daily, weekly, monthly scheduling
  • Business Days: Skip weekends automatically
  • Flexible Storage: Custom paths for timer metadata
  • Callbacks: onStart and onComplete hooks
  • Two Usage Modes: Plugin-based or action-based

Installation

npm install @quarry-systems/drift-timer

Quick Start

Plugin-Based Approach

import { ManagedCyclicGraph } from '@quarry-systems/managed-cyclic-graph';
import { mcgTimerPlugin, sleep, dailyAt } from '@quarry-systems/drift-timer';

const graph = new ManagedCyclicGraph()
  .use(mcgTimerPlugin)
  
  .node('wait5sec', {
    type: 'timernode',
    meta: {
      timer: sleep(5000)  // Wait 5 seconds
    }
  })
  
  .node('dailyReport', {
    type: 'timernode',
    meta: {
      timer: dailyAt(9, 0)  // Wait until 9:00 AM
    }
  })
  
  .build();

Action-Based Approach

import { ManagedCyclicGraph } from '@quarry-systems/managed-cyclic-graph';
import { createTimerAction, sleep, nextBusinessDay } from '@quarry-systems/drift-timer';

const graph = new ManagedCyclicGraph()
  .node('processOrder', {
    execute: [
      // ... process order logic
    ]
  })
  
  .node('waitForBusinessDay', {
    execute: [
      createTimerAction('waitForBusinessDay', nextBusinessDay(9, 0))
    ]
  })
  
  .node('sendReport', {
    execute: [
      // ... send report logic
    ]
  })
  
  .build();

API Reference

Helper Functions

sleep(ms: number)

Sleep for a specified duration in milliseconds.

sleep(5000)  // Sleep for 5 seconds
sleep(60000) // Sleep for 1 minute

waitUntil(date: Date | string | number)

Wait until a specific date/time.

waitUntil(new Date('2024-12-25T00:00:00'))
waitUntil('2024-12-25T00:00:00')
waitUntil(Date.now() + 3600000)  // 1 hour from now

dailyAt(hour: number, minute?: number)

Wait until the next occurrence of a specific time each day.

dailyAt(9, 0)   // Wait until 9:00 AM
dailyAt(17, 30) // Wait until 5:30 PM

weeklyAt(dayOfWeek: number, hour: number, minute?: number)

Wait until the next occurrence of a specific day and time each week.

weeklyAt(1, 9, 0)  // Monday at 9:00 AM (0=Sunday, 1=Monday, ...)
weeklyAt(5, 17, 0) // Friday at 5:00 PM

nextBusinessDay(hour?: number, minute?: number)

Wait until the next business day (skips weekends) at the specified time.

nextBusinessDay()       // Next business day at midnight
nextBusinessDay(9, 0)   // Next business day at 9:00 AM
nextBusinessDay(8, 30)  // Next business day at 8:30 AM

Configuration Options

interface TimerConfig {
  sleepMs?: number;              // Sleep duration in milliseconds
  waitUntil?: Date | string | number;  // Target date/time
  cronPattern?: CronPattern;     // Cron-like scheduling
  storePath?: string;            // Custom storage path
  onStart?: (ctx) => void;       // Callback when timer starts
  onComplete?: (ctx) => void;    // Callback when timer completes
}

Cron Pattern Options

interface CronPattern {
  type: 'daily' | 'weekly' | 'monthly' | 'custom';
  hour?: number;          // Hour (0-23)
  minute?: number;        // Minute (0-59)
  dayOfWeek?: number;     // Day of week (0-6, Sunday=0)
  dayOfMonth?: number;    // Day of month (1-31)
  skipWeekends?: boolean; // Skip Saturday/Sunday
  expression?: string;    // Custom cron expression (future)
}

Examples

Retry with Exponential Backoff

const graph = new ManagedCyclicGraph()
  .use(mcgTimerPlugin)
  
  .node('attempt1', {
    execute: [/* try operation */]
  })
  
  .node('wait1', {
    type: 'timernode',
    meta: { timer: sleep(1000) }  // Wait 1 second
  })
  
  .node('attempt2', {
    execute: [/* retry operation */]
  })
  
  .node('wait2', {
    type: 'timernode',
    meta: { timer: sleep(2000) }  // Wait 2 seconds
  })
  
  .node('attempt3', {
    execute: [/* final retry */]
  })
  
  .build();

Daily Report Generation

const graph = new ManagedCyclicGraph()
  .use(mcgTimerPlugin)
  
  .node('waitForMorning', {
    type: 'timernode',
    meta: {
      timer: dailyAt(8, 0)  // Every day at 8:00 AM
    }
  })
  
  .node('generateReport', {
    execute: [/* generate report */]
  })
  
  .node('sendReport', {
    execute: [/* send report */]
  })
  
  // Loop back to wait for next day
  .edge('sendReport', 'waitForMorning', 'any')
  
  .build();

Weekend-Aware Processing

const graph = new ManagedCyclicGraph()
  .use(mcgTimerPlugin)
  
  .node('checkData', {
    execute: [/* check for new data */]
  })
  
  .node('waitForBusinessDay', {
    type: 'timernode',
    meta: {
      timer: nextBusinessDay(9, 0)
    }
  })
  
  .node('processData', {
    execute: [/* process during business hours */]
  })
  
  .build();

With Callbacks

const graph = new ManagedCyclicGraph()
  .use(mcgTimerPlugin)
  
  .node('scheduledTask', {
    type: 'timernode',
    meta: {
      timer: {
        ...dailyAt(10, 0),
        onStart: (ctx) => {
          console.log('Timer started, waiting until 10:00 AM');
        },
        onComplete: (ctx) => {
          console.log('Timer completed, executing task now');
        }
      }
    }
  })
  
  .build();

Metadata Storage

Timer metadata is stored in the context at data.timer.{nodeId} by default:

{
  data: {
    timer: {
      wait5sec: {
        startTime: 1701234567890,
        targetTime: 1701234572890,
        duration: 5000,
        completed: true
      }
    }
  }
}

You can customize the storage path:

{
  timer: {
    ...sleep(5000),
    storePath: 'data.customPath.myTimer'
  }
}

Use Cases

  • Rate Limiting: Add delays between API calls
  • Retry Logic: Wait before retrying failed operations
  • Scheduled Tasks: Run tasks at specific times
  • Business Hours: Ensure operations run during business days
  • Cooldown Periods: Enforce waiting periods between actions
  • Batch Processing: Wait for batch windows
  • Compliance: Respect time-based regulations

Best Practices

  1. Use Business Day Scheduling for operations that should only run during work hours
  2. Add Callbacks for logging and monitoring timer events
  3. Store Metadata in custom paths when you need to track multiple timers
  4. Combine with Guards to create conditional timing logic
  5. Use Action-Based approach when mixing timers with other actions

License

ISC