Loading...
Loading...
Schedule periodic / recurring work in Encore Go using `cron.NewJob` from `encore.dev/cron`. Covers `Every: "1h"` interval syntax and `Schedule: "0 9 * * 1"` cron expressions.
npx skill4agent add encoredev/skills encore-go-croncron.NewJob//encore:apipackage cleanup
import (
"context"
"encore.dev/cron"
)
// 1. The endpoint to call (typically private: //encore:api private)
//encore:api private
func CleanupExpiredSessions(ctx context.Context) error {
// Cleanup logic
return nil
}
// 2. Package-level cron declaration
var _ = cron.NewJob("cleanup-sessions", cron.JobConfig{
Title: "Clean up expired sessions",
Schedule: "0 * * * *", // Every hour
Endpoint: CleanupExpiredSessions,
})| Field | Example | Description |
|---|---|---|
| | Simple interval. Must divide 24h evenly — |
| | Standard cron expression (5 fields, UTC). |
| Cron | Meaning |
|---|---|
| Every hour, on the hour |
| Daily at 02:00 UTC |
| Weekly on Sunday at midnight UTC |
| 04:00 UTC on the 15th of each month |
encore runprivateSchedulecron.NewJobEveryScheduleencore-go-pubsub