Skip to main content
import upnext

worker = upnext.Worker("my-worker")

@worker.cron("*/5 * * * *")  # Every 5 minutes
async def health_check():
    return {"status": "healthy"}
A cron job is a task that runs on a recurring schedule. UpNext uses standard cron syntax with an optional sixth field for seconds.

Define a cron job

Use the @worker.cron decorator with a cron expression:
@worker.cron("0 9 * * *")  # Every day at 9 AM
async def daily_report():
    return {"generated": True}

@worker.cron("*/30 * * * * *")  # Every 30 seconds (6-field syntax)
async def frequent_check():
    return {"checked": True}

Cron expression format

UpNext supports both 5-field and 6-field cron expressions:
Field5-field6-fieldValues
Seconds-1st0-59
Minutes1st2nd0-59
Hours2nd3rd0-23
Day of month3rd4th1-31
Month4th5th1-12
Day of week5th6th0-6 (Sun-Sat)
Common patterns:
*/5 * * * *        Every 5 minutes
0 */2 * * *        Every 2 hours
0 9 * * 1-5        Weekdays at 9 AM
*/10 * * * * *     Every 10 seconds (6-field)

Cron options

ParameterTypeDefaultDescription
schedulestrrequiredCron expression
namestrNoneCustom display name
timeoutfloat1800Maximum execution time in seconds
missed_run_policyMissedRunPolicyLATEST_ONLYHow to handle missed runs
max_catch_up_secondsfloatNoneMax time window for catching up missed runs

Missed run policies

If a worker was down and missed scheduled runs, the missed_run_policy controls what happens when it comes back:
  • LATEST_ONLY (default) — Run only the most recent missed execution, skip the rest.
  • RUN_ALL — Run every missed execution in order, bounded by max_catch_up_seconds.
from shared.contracts.common import MissedRunPolicy

@worker.cron(
    "0 * * * *",
    missed_run_policy=MissedRunPolicy.RUN_ALL,
    max_catch_up_seconds=3600,  # Catch up at most 1 hour
)
async def hourly_sync():
    ...

Using context in cron jobs

Cron jobs have full access to the execution context, just like tasks:
@worker.cron("*/5 * * * *")
async def monitored_check():
    ctx = upnext.get_current_context()
    ctx.set_progress(50, "Running checks")
    ctx.send_log("info", "Health check running")
    return {"status": "ok"}

Next: Events

Pub/sub handlers that trigger when an event is published.