cron-jobs

Langlebige Cron-Jobs mit Rivet Actors: schedule.after- und schedule.at-Timer überleben Neustarts und Abstürze, plus erneutes Aktivieren wiederkehrender Jobs und idempotente Handler.

npx skills add https://github.com/rivet-dev/skills --skill cron-jobs

Cron Jobs and Scheduled Tasks

IMPORTANT: Before doing anything, you MUST read BASE_SKILL.md in this skill's directory. It contains essential guidance on debugging, error handling, state management, deployment, and project setup. Those rules and patterns apply to all RivetKit work. Everything below assumes you have already read and understood it.

Working Examples

If you need a reference implementation, read the raw working example code in these templates:

Rivet Actor schedules are durable actor-local timers. They survive actor sleep, restarts, upgrades, deploys, and crashes without a separate cron service.

Choose a schedule type

APIUse it for
c.schedule.after(delayMs, action, ...args)One-time work after a relative delay.
c.schedule.at(timestamp, action, ...args)One-time work at an exact Unix timestamp in milliseconds.
c.cron.set({ ... })Named calendar recurrence in an IANA timezone.
c.cron.every({ ... })Named fixed intervals of at least 5 seconds.

All callbacks are ordinary actions on the same actor. Keep the action name fixed in your code rather than accepting an arbitrary action name from a client.

See Schedule & Cron for the full API, history, cancellation, failure behavior, and limits.

Calendar job

Use cron.set instead of manually re-arming a one-shot action:

Install fixed background jobs in onCreate so setup runs once per actor. The job name remains an upsert key, so a later cron.set call updates the existing job rather than creating a duplicate. cron.set also handles timezone and daylight-saving transitions.

Fixed-interval job

Use cron.every for frequent work such as presence sweeps or cache refreshes:

await c.cron.every({
  name: "presence-sweep",
	interval: 15_000, // Minimum 5 seconds.
  action: "sweepPresence",
  maxHistory: 25,
});

Intervals remain anchored to scheduled deadlines rather than drifting by the action's runtime. If a previous run is still active, the overlapping occurrence is skipped.

Cancellation and updates

Keep the ID returned by a one-shot schedule when it may need cancellation:

const id = await c.schedule.after(60_000, "expireSession", sessionId);
await c.schedule.cancel(id);

Recurring jobs are managed by name:

await c.cron.delete("presence-sweep");

Calling cron.set or cron.every again with the same name replaces its configuration.

Failure and idempotency

Keep scheduled actions idempotent when duplicate work would be harmful. See Execution behavior for retry behavior and workflow guidance.

Topology

Use a singleton actor key for one global job, such as jobs["daily-report"]. Use an actor per user or resource for isolated reminders, trials, billing periods, or other per-entity schedules.

Reference Map

Actors

Cli

Clients

Cookbook

Deploy

General

Self Hosting

Mehr Skills von rivet-dev

ai-agent
rivet-dev
Erstelle ein KI-Agent-Backend mit persistentem Speicher: ein Rivet Actor pro Konversation, Warteschlangen-Nachrichtenverarbeitung und Streaming von LLM-Antworten als Echtzeit-Ereignisse.
official
ai-agent-workspace
rivet-dev
Gib jedem KI-Agenten seinen eigenen Computer: einen persistenten Arbeitsbereich mit Dateisystem, Prozessen, Shells, Netzwerk und Agentensitzungen auf einem leichten prozessinternen…
official
chat-room
rivet-dev
Erstelle ein Echtzeit-Chatroom-Backend mit Rivet Actors: ein Actor pro Raum, SQLite-gestützter Nachrichtenverlauf und WebSocket-Broadcast an jeden verbundenen Client.
official
collaborative-text-editor
rivet-dev
Baue ein kollaboratives Texteditor-Backend mit Yjs-CRDTs und Rivet-Actors: Pro-Dokument-Actors leiten Sync- und Awareness-Updates weiter und speichern Snapshots.
official
live-cursors
rivet-dev
Live-Cursor und Multiplayer-Präsenz mit Rivet Actors: verbindungsspezifischer Cursor-Zustand, Echtzeit-Updates über Events oder rohe WebSockets sowie Drosselung.
official
per-tenant-database
rivet-dev
Multi-Tenant-Datenisolierung mit einem Rivet Actor pro Tenant: Der Actor-Key ist die Tenant-ID, sodass jeder Tenant seinen eigenen isolierten Datensatz und eigene Migrationen erhält.
official
rivetkit-client-javascript
rivet-dev
JavaScript-Client zum Verbinden mit Rivet Actors über zustandslose oder zustandsbehaftete Verbindungen. Unterstützt Browser-, Node.js- und Bun-Umgebungen mit automatischer Endpunkt-Erkennung über Umgebungsvariablen oder explizite Konfiguration. Bietet zwei Interaktionsmodi: zustandslose Aktionsaufrufe für unabhängige Anfragen und zustandsbehaftete Verbindungen mit Echtzeit-Ereignisabonnements. Enthält Low-Level-HTTP- und WebSocket-Zugriff für Actors, die onRequest- oder onWebSocket-Handler implementieren. Bietet zusammengesetzte arraybasierte...
official
rivetkit-client-react
rivet-dev
React-Client zur Verbindung mit Rivet Actors mittels Hooks und Echtzeit-Zustandsverwaltung. Erstelle typisierte Hooks mit createRivetKit() und verbinde dich mit Actor-Instanzen über useActor() mit Schlüsseln und optionalen Parametern. Abonniere Actor-Ereignisse mit useEvent() und überwache den Verbindungslebenszyklus über connStatus und error-Zustände. Verwende createClient() für zustandslose Einzelaufrufe, Actor-Erkennungsmethoden (get, getOrCreate, create, getForId) sowie Low-Level-HTTP/WebSocket-Zugriff. Unterstützt zusammengesetzte Array-Schlüssel...
official