cron-jobs

โดย rivet-dev

Durable cron jobs with Rivet Actors: schedule.after and schedule.at timers survive restarts and crashes, plus re-arming recurring jobs and idempotent handlers.

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

Skills เพิ่มเติมจาก rivet-dev

ai-agent
rivet-dev
สร้างแบ็กเอนด์ AI agent ที่มีหน่วยความจำถาวร: หนึ่ง Rivet Actor ต่อการสนทนา การจัดการข้อความในคิว และการสตรีมการตอบสนองของ LLM เป็นเหตุการณ์แบบเรียลไทม์
official
ai-agent-workspace
rivet-dev
มอบคอมพิวเตอร์ส่วนตัวให้กับเอเจนต์ AI ทุกตัว: พื้นที่ทำงานถาวรที่มีระบบไฟล์ โปรเซส เชลล์ เครือข่าย และเซสชันของเอเจนต์บนระบบในกระบวนการที่มีน้ำหนักเบา…
official
chat-room
rivet-dev
สร้างแบ็กเอนด์ห้องแชทแบบเรียลไทม์ด้วย Rivet Actors: หนึ่ง actor ต่อหนึ่งห้อง, ประวัติข้อความที่ใช้ SQLite, และการกระจายสัญญาณ WebSocket ไปยังทุกไคลเอนต์ที่เชื่อมต่อ
official
collaborative-text-editor
rivet-dev
สร้างแบ็กเอนด์ของโปรแกรมแก้ไขข้อความแบบทำงานร่วมกันด้วย Yjs CRDTs และ Rivet Actors: ตัวแทนต่อเอกสารจะถ่ายทอดการอัปเดตการซิงค์และการรับรู้ และบันทึกสแนปช็อต
official
live-cursors
rivet-dev
เคอร์เซอร์สดและการแสดงสถานะผู้เล่นหลายคนด้วย Rivet Actors: สถานะเคอร์เซอร์ต่อการเชื่อมต่อ อัปเดตแบบเรียลไทม์ผ่านอีเวนต์หรือ WebSockets ดิบ และการจำกัดความถี่
official
per-tenant-database
rivet-dev
การแยกข้อมูลแบบหลายผู้เช่าโดยใช้ Rivet Actor หนึ่งตัวต่อผู้เช่า: คีย์ของแอคเตอร์คือรหัสผู้เช่า ดังนั้นผู้เช่าแต่ละรายจะได้รับชุดข้อมูลและการย้ายข้อมูลที่แยกออกจากกัน
official
rivetkit-client-javascript
rivet-dev
ไคลเอนต์ JavaScript สำหรับเชื่อมต่อกับ Rivet Actors ด้วยการเชื่อมต่อแบบไร้สถานะหรือมีสถานะ รองรับสภาพแวดล้อมเบราว์เซอร์ Node.js และ Bun พร้อมการตรวจจับเอนด์พอยต์อัตโนมัติผ่านตัวแปรสภาพแวดล้อมหรือการกำหนดค่าแบบชัดเจน มีโหมดการโต้ตอบสองแบบ: การเรียกแอคชันแบบไร้สถานะสำหรับคำขออิสระ และการเชื่อมต่อแบบมีสถานะพร้อมการสมัครรับเหตุการณ์แบบเรียลไทม์ รวมถึงการเข้าถึง HTTP และ WebSocket ระดับต่ำสำหรับแอคเตอร์ที่ใช้ตัวจัดการ onRequest หรือ onWebSocket ให้การเข้าถึงแบบอาร์เรย์ผสม...
official
rivetkit-client-react
rivet-dev
React client สำหรับเชื่อมต่อกับ Rivet Actors โดยใช้ hooks และการจัดการสถานะแบบเรียลไทม์ สร้าง typed hooks ด้วย createRivetKit() และเชื่อมต่อกับอินสแตนซ์ของ actor โดยใช้ useActor() พร้อม keys และพารามิเตอร์เสริม สมัครรับอีเวนต์ของ actor ด้วย useEvent() และตรวจสอบวงจรการเชื่อมต่อผ่านสถานะ connStatus และ error states ใช้ createClient() สำหรับการเรียกแบบ stateless แบบครั้งเดียว, วิธีการค้นหา actor (get, getOrCreate, create, getForId), และการเข้าถึง HTTP/WebSocket ระดับต่ำ รองรับ compound array keys...
official