Scheduling Cron Jobs in Encore.ts

VerifiedSafe

Learn to create scheduled tasks in Encore.ts using CronJob, covering every/schedule formats and best practices.

Sby Skills Guide Bot
DevelopmentIntermediate
9/5/2026
Claude CodeCursorWindsurfCopilotCodex
#encore#cron-jobs#scheduling#typescript#backend

Recommended for

Automated summary

Explains how to declare recurring scheduled jobs in Encore.ts by attaching a CronJob to an existing api() endpoint.

Strengths

  • Shows the exact package-level declaration pattern with new CronJob and stresses that the endpoint must be defined first
  • Clarifies the split between every (interval that must divide 24h evenly) and schedule (5-field cron in UTC)
  • Includes a table of common cron expressions that can be reused directly
  • Flags real production gotchas: crons never fire under local encore run, endpoints should be expose: false, and logic must be idempotent

Limitations

  • Covers Encore.ts only, with no guidance for Encore Go or other frameworks
  • Does not address error handling, retries, or how to observe cron executions
  • Assumes the api() endpoint already exists and shows no business logic implementation
When to use it

Reach for it whenever a user wants code to run on a fixed interval or at a specific time of day inside an Encore.ts app.

When not to use it

Skip it when the background work should be event-driven rather than time-driven, or when the project is not built on Encore.

Security analysis

Safe
Quality score88/100

This skill is purely declarative documentation for using Encore.ts CronJob with no executable commands, destructive actions, network calls, or sensitive data handling. It only provides code examples and scheduling guidance.

No concerns found

How this analysis is made

Examples

Daily aggregation job
In my Encore.ts service I need a job that aggregates the previous day's orders every day at 02:00 UTC. Create the internal endpoint and wire up the CronJob.
Hourly interval job
Add a scheduled job to my Encore app that runs every 30 minutes to refresh a cache, using the every syntax.
Weekly report cron
Set up a cron in Encore.ts that runs every Monday at 09:00 UTC to generate a weekly report, and make sure the endpoint can't be called externally.

name: encore-cron description: >- Schedule periodic / recurring work in Encore.ts using CronJob from encore.dev/cron. Covers every: "1h" interval syntax and schedule: "0 9 * * 1" cron expressions. when_to_use: >- User wants to run a job on a schedule — anything with the words schedule, scheduled, daily, hourly, weekly, periodic, recurring, every N minutes/hours, "at HH:MM UTC", midnight, batch job, aggregation job, nightly, cleanup job, or background work that runs on a timer rather than in response to a request. Trigger phrases: "every day at 02:00 UTC", "daily aggregation", "run hourly", "scheduled task", "cron", "nightly cleanup", "on a schedule".

Encore Cron Jobs

Instructions

A CronJob declaration in Encore.ts ties a schedule to an existing api(...) endpoint. The endpoint runs at the chosen cadence. Declare the CronJob at package level — not inside a function.

import { CronJob } from "encore.dev/cron";
import { api } from "encore.dev/api";

// 1. The endpoint to call (typically internal: expose: false)
export const aggregateDailyOrders = api(
  { expose: false },
  async (): Promise<void> => {
    // Aggregation logic
  }
);

// 2. Package-level cron declaration
const _ = new CronJob("aggregate-daily-orders", {
  title: "Aggregate orders for the previous day",
  schedule: "0 2 * * *",  // 02:00 UTC every day
  endpoint: aggregateDailyOrders,
});

Schedule Formats

| Field | Example | Description | |---|---|---| | every | "1h", "30m", "6h" | Simple interval. Must divide 24h evenly — "7h" is invalid. | | schedule | "0 9 * * 1" | Standard cron expression (5 fields, UTC). |

Common cron expressions

| Cron | Meaning | |---|---| | "0 * * * *" | Every hour, on the hour | | "0 2 * * *" | Daily at 02:00 UTC | | "0 0 * * 0" | Weekly on Sunday at midnight UTC | | "0 4 15 * *" | 04:00 UTC on the 15th of each month |

Important behaviour

  • Cron jobs do not execute when running locally with encore run. Only deployed environments fire crons.
  • The cron endpoint should be expose: false so it can't be triggered externally — only the cron scheduler should call it.
  • All times in schedule are UTC. Convert from local time when designing the schedule.
  • The endpoint must already exist at module load — declare it before the CronJob.

Guidelines

  • Use every for "run on a regular interval" (must divide 24h).
  • Use schedule for specific times of day or days of week.
  • Keep endpoint logic idempotent: a cron may fire late or be retried in a redeploy window.
  • For event-driven background work (not time-driven), use the encore-pubsub skill instead.

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/scheduling-cron-jobs-in-encore-ts-mtnxbry5/download' --output '.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5/SKILL.md.part' && mv '.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5/SKILL.md.part' '.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5/SKILL.md' && test -s '.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/encore-cron' && cp -R '.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5' '.claude/skills/encore-cron'

Cursor
test -f '.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5/SKILL.md' && test -s '.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/encore-cron' && cp -R '.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5' '.cursor/skills/encore-cron'

Codex
test -f '.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5/SKILL.md' && test -s '.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/encore-cron' && cp -R '.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5' '.agents/skills/encore-cron'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5'

openskills read 'scheduling-cron-jobs-in-encore-ts-mtnxbry5'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/scheduling-cron-jobs-in-encore-ts-mtnxbry5/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills