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

workflow-cron-start

v1.0.4

Published

Start workflows on a cron schedule with the Workflow Dev Kit

Readme

workflow-cron-start

Schedule workflows to run on a cron schedule with the Workflow DevKit.

What This Does

Provides a simple API for creating recurring cron-scheduled workflows:

  • cronStart() - Start a workflow on a cron schedule
  • cronEnd() - Cancel a running cron workflow

Each cron trigger creates a separate workflow run with its own runId, enabling proper auditing and visibility.

Installation

npm install workflow-cron-start

Note: workflow-cron-sleep is included as a dependency and doesn't need to be installed separately.

Setup

Configure Next.js

Use withCronWorkflow in your next.config.ts (this wraps the standard withWorkflow):

// next.config.ts
import { withCronWorkflow } from "workflow-cron-start/next"
import type { NextConfig } from "next"

const nextConfig: NextConfig = {
  // your config
}

export default withCronWorkflow(nextConfig)

Monorepo Setup (pnpm/yarn workspaces)

The package automatically sets outputFileTracingRoot to the Next.js project directory, which works for most setups. If you have shared packages outside the Next.js app that need to be traced, you may need to override it to point to your monorepo root:

// next.config.ts
import { withCronWorkflow } from "workflow-cron-start/next"
import path from "path"
import { fileURLToPath } from "url"

const __dirname = path.dirname(fileURLToPath(import.meta.url))

const nextConfig = {
  // Only needed if you have shared packages outside the Next.js app
  outputFileTracingRoot: path.resolve(__dirname, "../.."),
}

export default withCronWorkflow(nextConfig)

Quick Start

1. Define your workflow

// src/lib/my-workflow.ts
export async function sendReport(email: string) {
    "use workflow"
    
    console.log(`Sending report to ${email}`)
    // Your workflow logic here
    
    return { success: true, email }
}

2. Start the cron workflow

// src/app/api/start-cron/route.ts
import { cronStart } from "workflow-cron-start"
import { sendReport } from "@/lib/my-workflow"

export async function POST() {
    const run = await cronStart(sendReport, ["[email protected]"], {
        cron: "0 9 * * *",        // Every day at 9 AM
        timezone: "America/New_York"
    })
    
    // Save this runId to cancel the cron later
    return Response.json({ runId: run.runId })
}

3. Cancel the cron workflow

// src/app/api/stop-cron/route.ts
import { cronEnd } from "workflow-cron-start"

export async function POST(request: Request) {
    const { runId } = await request.json()
    
    await cronEnd(runId)
    
    return Response.json({ cancelled: true })
}

API Reference

cronStart(workflow, args, options)

Start a workflow on a cron schedule.

import { cronStart } from "workflow-cron-start"

const run = await cronStart(myWorkflow, [arg1, arg2], {
    cron: "0 9 * * *",
    timezone: "America/New_York",
    onError: "continue"
})

console.log(run.runId) // Save this to cancel later

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | workflow | Function | The workflow function to schedule | | args | Array | Arguments to pass to the workflow on each execution | | options | CronOptions | Scheduling options (see below) |

Returns: Promise<{ runId: string }>

cronEnd(runId)

Cancel a running cron workflow.

import { cronEnd } from "workflow-cron-start"

await cronEnd("wrun_01ABC123...")

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | runId | string | The run ID returned from cronStart() |

Returns: Promise<{ runId: string, cancelled: boolean }>

Throws: Error if the run ID does not correspond to a cron workflow.

CronOptions

| Property | Type | Required | Description | |----------|------|----------|-------------| | cron | string | Yes | Cron expression (e.g., "0 9 * * *") | | timezone | string | No | IANA timezone (e.g., "America/New_York", "UTC") | | onError | "continue" | "stop" | No | Error handling behavior (default: "continue") |

withCronWorkflow(nextConfig, options?)

Next.js config wrapper. Use this instead of withWorkflow from the Workflow Dev Kit.

import { withCronWorkflow } from "workflow-cron-start/next"

export default withCronWorkflow({
  // your Next.js config
})

Timezone Behavior

Important: When no timezone is specified, the cron expression uses the server's local timezone, which varies by deployment region.

For predictable behavior, always specify a timezone:

await cronStart(myWorkflow, [args], {
    cron: "0 9 * * *",
    timezone: "America/New_York"  // Always specify this
})

Error Handling

| onError | Behavior | |-----------|----------| | "continue" (default) | Log the error, continue to next scheduled run | | "stop" | Stop the cron loop and propagate the error |

Cron Expression Reference

| Expression | Description | |------------|-------------| | * * * * * | Every minute | | 0 9 * * * | Every day at 9:00 AM | | 30 8 * * 1 | Every Monday at 8:30 AM | | 0 0 1 * * | First day of every month at midnight | | 0 */2 * * * | Every 2 hours | | 0 9 * * 1-5 | Weekdays at 9:00 AM |

Architecture

┌──────────────────────────────────────────────────────────┐
│           Cron Scheduler Workflow (runs forever)         │
│                                                          │
│  ┌─────────────┐                                         │
│  │ cronSleep() │  ← Waits until next cron trigger        │
│  └──────┬──────┘                                         │
│         │                                                │
│         ▼                                                │
│  ┌─────────────────┐      ┌─────────────────────────┐    │
│  │ Trigger Step    │ ───► │ New Workflow Run        │    │
│  │ (HTTP request)  │      │ (wrun_xxx - separate!)  │    │
│  └─────────────────┘      └─────────────────────────┘    │
│         │                                                │
│         └────────────────────┐                           │
│                              │                           │
│         ┌────────────────────┘                           │
│         │                                                │
│         ▼                                                │
│      (repeat)                                            │
│                                                          │
└──────────────────────────────────────────────────────────┘

Each cron trigger creates a separate workflow run with its own runId, making it easy to:

  • Track individual executions
  • Debug specific runs
  • View execution history

Requirements

  • Next.js >= 13 (App Router)
  • workflow package (Workflow Dev Kit) >= 4.0.0

Limitations

This package currently only supports Next.js. It uses:

  • Next.js build tooling (Turbopack/Webpack loaders)
  • App Router file conventions (src/app/)
  • withCronWorkflow which wraps workflow/next

Support for other frameworks may be added in future versions.

License

MIT