mastra-schedules
Skill2 starsChanged 29 days agoApache-2.0View on GitHub
Run Mastra agents and workflows on a cron cadence: create, list, update, pause, resume, run, and delete persisted schedules through mastra.schedules, declare a schedule field on createWorkflow, send threaded schedule fires as signals into a conversation, and hook prepare, onFinish, onError, and onAbort. Use this skill whenever the user wants a daily summary, an hourly check, a weekly report, a recurring nudge into a chat thread, a cron job for an agent or workflow, or needs to pause a misfiring schedule in production. Triggers on mastra.schedules, schedules.create, cron, timezone, scheduled workflow, schedule field on createWorkflow, pauseSchedule, resumeSchedule, wf_ schedule id, agent_ schedule id, threadless versus threaded schedule, SchedulerWorker, MASTRA_WORKERS scheduler, Studio schedules view. Also triggers when schedules do not fire on serverless hosts or with a server adapter.
In this repository46 other files it gives its agents.
- mastra-a2a-acpSkill
- mastra-agent-approval-hitlSkill
- mastra-agentic-uiSkill
- mastra-agent-skillsSkill
- mastra-agentsSkill
- mastra-authSkill
- mastra-browserSkill
- mastra-build-playbookSkill
- mastra-channelsSkill
- mastra-classifierSkill
- mastra-cli-apiSkill
- mastra-client-sdkSkill
- mastra-datasets-experimentsSkill
- mastra-deploymentSkill
- mastra-evalsSkill
- mastra-file-based-agentsSkill
- mastra-framework-integrationSkill
- mastra-guideSkill
- mastra-harnessSkill
- mastra-knowledgeSkill
- mastra-mcpSkill
- mastra-memorySkill
- mastra-migrationsSkill
- mastra-modelsSkill
- mastra-multi-agentSkill
- mastra-observabilitySkill
- mastra-observational-memorySkill
- mastra-platformSkill
- mastra-processors-guardrailsSkill
- mastra-project-setupSkill
- mastra-ragSkill
- mastra-semantic-recallSkill
- mastra-serverSkill
- mastra-signalsSkill
- mastra-storageSkill
- mastra-streamingSkill
- mastra-structured-outputSkill
- mastra-studio-editorSkill
- mastra-tool-integrationsSkill
- mastra-toolsSkill
- mastra-troubleshootingSkill
- mastra-vector-storesSkill
- mastra-voiceSkill
- mastra-workflowsSkill
- mastra-workflow-suspend-resumeSkill
- mastra-workspace-sandboxSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 104
Verify the API: If node_modules/@mastra/ exists, read node_modules/@mastra/core/dist/docs/ and the installed mastra.schedules types.
- Very specific: line 107
Write the cron and timezone: Always set timezone in production.
- Very specific: line 109
Give a stable
id: when code must look the schedule up later. - Very specific: line 112
Operate: Use pause, resume, and run from code, client.pauseSchedule() from a client, or Studio at /workflows/schedules.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Mastra Schedules
Fire agents and workflows on a cron cadence with persisted, pausable schedules, and deploy the scheduler where it can actually tick.
When to use
- An agent should run on a cadence (status checks, daily summaries, periodic triage)
- A recurring prompt should land in an existing conversation thread
- A workflow should start on a cron with fixed input
- Schedules must be created, edited, paused, or deleted at runtime (from code, a UI, or the client SDK)
- Computing fire-time parameters, or skipping a fire, with a
preparehook - Debugging schedules that never fire or fire at the wrong time
When NOT to use
- One-off delayed work or slow tools inside a run (use
mastra-harnessbackground tasks) - Sending signals or notifications into a thread outside a cron (use
mastra-signals) - Defining workflow steps, branching, and suspend/resume (use
mastra-workflowsandmastra-workflow-suspend-resume) - Schedules for agents defined as files (use
mastra-file-based-agents) - Worker containers and hosting targets (use
mastra-deployment) - Inngest-native cron functions (use
mastra-workflowswith the Inngest integration)
Required inputs
- Target: an agent ID with a prompt, or a workflow ID with input data
- Cadence as cron (5, 6, or 7 parts, or
@dailystyle nicknames) and an IANA timezone - Threadless (isolated
generate()run) or threaded (threadIdplusresourceId) - A storage adapter with the schedules domain:
@mastra/libsql,@mastra/pg,@mastra/mysql,@mastra/mongodb,@mastra/convex, or@mastra/spanner - The host: long-lived server, server adapter, split workers, or serverless
The framework: one service, two declaration styles
| Runtime schedules | Declarative workflow schedules | |
| Created by | mastra.schedules.create({...}) | schedule field on createWorkflow |
| Targets | Agents (agentId) or workflows (workflowId) | That workflow |
| ID | agent_<slug or uuid> or schedule_<slug or uuid> | wf_<workflowId> or wf_<workflowId>__<id> |
| Edit | update(), pause(), resume(), delete() | Change code and redeploy. Pause and resume still work. |
| Storage | Persisted rows | Persisted rows, upserted on boot |
import { Mastra } from '@mastra/core'
import { Agent } from '@mastra/core/agent'
import { LibSQLStore } from '@mastra/libsql'
const pinger = new Agent({
id: 'pinger',
name: 'Pinger',
instructions: 'Report the current system status in one sentence.',
model: 'openai/gpt-6.1-sol',
})
const mastra = new Mastra({
agents: { pinger },
storage: new LibSQLStore({ id: 'mastra-storage', url: 'file:./mastra.db' }),
})
// Threadless: each fire is an isolated agent.generate() run
await mastra.schedules.create({
id: 'hourly-status',
agentId: 'pinger',
cron: '0 * * * *',
timezone: 'America/New_York',
prompt: 'Give me a status update.',
})
// Threaded: each fire is a signal into the conversation
await mastra.schedules.create({
agentId: 'pinger',
cron: '0 9 * * 1-5',
prompt: 'Summarize anything new since yesterday.',
threadId: 'thread-123',
resourceId: 'user-456',
ifActive: { behavior: 'discard' },
ifIdle: { behavior: 'wake' },
})Delivery is best-effort
The scheduler claims an occurrence, advances nextFireAt, then publishes with up to three attempts. A crash or exhausted attempts can skip an occurrence, and skipped occurrences are never replayed. Retries can publish duplicates. Design targets to tolerate both. completed means the cron has no future occurrence, not that the run succeeded.
Workflow
- Verify the API. If
node_modules/@mastra/exists, readnode_modules/@mastra/core/dist/docs/and the installedmastra.schedulestypes. Otherwise fetchhttps://mastra.ai/docs/harness/schedules.md,https://mastra.ai/reference/schedules/overview.md, andhttps://mastra.ai/docs/workflows/scheduled-workflows.md. Schedules need@mastra/core@1.50.0or later. Trust these over memory. - Configure storage with the schedules domain on
new Mastra({ storage }). - Pick the style. Fixed workflow cadence in code:
scheduleoncreateWorkflow. Anything created per user or at runtime:mastra.schedules.create(). - Write the cron and timezone. Always set
timezonein production. Validate the cron by creating the schedule (invalid crons throw). - Choose threadless or threaded for agents. Threaded fires need
resourceIdand accept signal fields (signalType,tagName,attributes,ifActive,ifIdle). - Give a stable
idwhen code must look the schedule up later. IDs normalize toagent_<slug>orschedule_<slug>. - Add hooks under
new Mastra({ schedules: { prepare, onFinish, onError, onAbort } })when fire-time values or outcome handling are needed. Branch onagentId. - Make the scheduler tick. The
mastra buildserver starts it. With a server adapter, callmastra.startWorkers()after listening. On serverless, use Inngest cron instead. - Operate. Use
pause,resume, andrunfrom code,client.pauseSchedule()from a client, or Studio at/workflows/schedules. - Verify with
mastra.schedules.run(id)and inspect trigger history in Studio.
Deep dive: declarative workflow schedules
import { createWorkflow, createStep } from '@mastra/core/workflows'
import { z } from 'zod'
const sendReport = createStep({
id: 'send-report',
inputSchema: z.object({ userId: z.string() }),
outputSchema: z.object({ ok: z.boolean() }),
execute: async ({ inputData }) => ({ ok: true }),
})
export const dailyReport = createWorkflow({
id: 'daily-report',
inputSchema: z.object({ userId: z.string() }),
outputSchema: z.object({ ok: z.boolean() }),
schedule: {
cron: '0 9 * * *',
timezone: 'America/New_York',
inputData: { userId: 'system' },
},
})
.then(sendReport)
.commit()Pass an array of entries with unique id values for several cadences. On redeploy, a changed cron or timezone recomputes nextFireAt, changed inputData patches in place, a user-set pause is preserved, and removed entries are deleted.
Split deployments: when MASTRA_WORKERS is set (even to false), createWorkflow builds scheduled workflows on the evented engine, which needs @mastra/libsql or @mastra/pg. Run exactly one scheduler worker.
Failure patterns
- Schedules never fire with a server adapter. Adapters do not start workers. Call
mastra.startWorkers()after the server listens. - Schedules never fire on Vercel, Netlify, Lambda, or Workers. The tick loop needs a long-lived process. Use
@mastra/inngestcron or a long-lived host. - Storage has no schedules domain. Upstash, DynamoDB, D1, ClickHouse, and Redis lack it. Use libSQL, Postgres, MySQL, MongoDB, Convex, or Spanner.
- Fires at the wrong hour. No
timezone, so the host locale applies. Set an IANA timezone. - Duplicate fires. More than one scheduler worker, or publish retries. Run one scheduler and make targets idempotent.
threadIdwithoutresourceId. Threaded schedules require both.signalType,ifActive, andifIdlerequirethreadId.- Trying to move a threaded schedule.
threadIdandresourceIdare not patchable. Create a new schedule and delete the old one. - Agent-only patch on a workflow schedule (
prompt,ifIdle) throws. - Editing code does not unpause. A paused declarative schedule stays paused until
resumeScheduleor Studio Resume. - Expecting
onFinishat run end for threaded schedules. It fires when the signal starts the run. Errors after that surface on the thread's run. - Backlog expected after resume. Resume recomputes from now. Missed occurrences are not replayed.
- Confusing Mastra Code
/scheduleswithmastra.schedules. The former is process-local and not persisted.
Output format
A finished schedule delivery contains:
- Storage with the schedules domain on the
Mastrainstance - Either a
schedulefield on the workflow or amastra.schedules.create()call with a stableid - Explicit
timezoneon every schedule - Hooks in
new Mastra({ schedules })if fire-time values or outcome handling are required - A note on how the scheduler runs (built server,
startWorkers(), scheduler worker, or Inngest) - Evidence: a manual
run()and the trigger row in Studio
Reference files
references/api.md-mastra.schedulesmethods, agent and workflow input fields, patch rules, hooks, declarative fields, IDs, topology.references/examples.md- Daily threaded summary, per-user schedules with hooks, multi-cadence workflow, client pause and resume.references/checklist.md- Schedule production checklist.
Live docs
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

