render-cron-jobs

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Render Cron Jobs

Render Cron Jobs

This skill covers Cron Job services on Render: how schedules run, what the platform guarantees, and how they differ from workers and workflows. Pair it with Blueprint and deploy skills when authoring
render.yaml
or Dashboard settings.
本技能涵盖Render上的Cron Job服务:计划任务的运行方式、平台提供的保障,以及它们与工作者(worker)和工作流(workflow)的区别。在编写
render.yaml
或配置控制台(Dashboard)设置时,可搭配Blueprint和部署技能使用。

When to Use

适用场景

  • Scheduled work that starts on a cron, runs a command, and exits when finished
  • Choosing between cron, background worker, or workflow for periodic or long-running jobs
  • Blueprint fields for
    type: cron
    ,
    schedule
    , and commands
  • Constraints: no disk, single concurrent run, 12-hour max duration, private-network outbound only
  • UTC scheduling pitfalls (expressions are not local time)
Expression cheat sheets, framework
startCommand
examples, and Heroku Scheduler migration mapping live under
references/
.
  • 基于cron启动、运行命令并在完成后退出的定时工作
  • 为周期性或长时间运行的任务选择cron、后台工作者(background worker)或工作流(workflow)
  • type: cron
    对应的Blueprint字段、
    schedule
    及命令配置
  • 限制条件:无磁盘存储、单次并发运行、最长运行时长12小时、仅支持私有网络出站流量
  • UTC调度陷阱(表达式使用非本地时间)
表达式速查表、框架
startCommand
示例以及Heroku Scheduler迁移映射可在
references/
目录下查看。

Configuration

配置说明

  • Schedule: a cron expression evaluated in UTC, not the team’s local timezone. All times in the Dashboard and Blueprints are UTC.
  • Command: any valid Linux shell command or bash script path. The process must exit when work is done because longer runs consume more billable compute. Confirm current details at Render pricing.
  • Source:
    • Git repository — Render builds on push (same deploy model as other repo-backed services); the built artifact runs on each scheduled invocation.
    • Prebuilt Docker image — the image is pulled before each run and is not retained between runs (no warm cache of the image layer set across invocations in the same way as a long-lived service).
  • 计划(Schedule):基于UTC解析的cron表达式,而非团队的本地时区。控制台和Blueprint中的所有时间均为UTC时间。
  • 命令(Command):任何有效的Linux shell命令或bash脚本路径。任务完成后进程必须退出,因为运行时间越长,消耗的计费计算资源越多。可访问Render pricing查看最新定价详情。
  • 来源(Source):
    • Git仓库——Render会在代码推送时构建(与其他基于仓库的服务部署模式相同);构建后的产物会在每次计划调用时运行。
    • 预构建Docker镜像——每次运行前都会拉取镜像,且运行之间不会保留镜像(与长期运行的服务不同,多次调用之间不会缓存镜像层)。

Constraints

限制条件

  • No persistent disk — cron job services cannot provision or attach Render persistent disks; plan for object storage or databases instead.
  • Single-run guarantee — at most one active run per cron service at a time. A new scheduled tick does not start a second overlapping instance.
  • Maximum run length: 12 hours per invocation.
  • Pricing: Running cron jobs incurs an additional cost. Confirm current details at Render pricing.
  • Private network: cron jobs can send traffic to other services on the private network; they cannot receive inbound private-network connections (no internal hostname for accepting traffic from other services).
  • 无持久化磁盘——cron job服务无法配置或挂载Render持久化磁盘;建议使用对象存储或数据库替代。
  • 单次运行保障——每个cron服务同一时间最多一个活跃运行实例。新的计划触发不会启动第二个重叠实例。
  • 最长运行时长:每次调用最长12小时。
  • 定价:运行cron job会产生额外费用。可访问Render pricing查看最新定价详情。
  • 私有网络:cron job可以向私有网络中的其他服务发送流量;但无法接收私有网络的入站连接(没有用于接收其他服务流量的内部主机名)。

Execution Behavior

执行行为

  • Manual “Trigger Run” while a run is active: Render cancels the active run, then starts a new one.
  • New Git build / deploy does not affect a run already in progress—the in-flight process keeps using the revision it started with until it exits.
  • Docker-based crons: the image is pulled fresh for each run; do not assume layer or image reuse across invocations like a continuously running container.
  • UTC everywhere: cron expressions and “midnight” in docs mean UTC. A common mistake is copying a local-time schedule into the expression without converting to UTC.
  • 当运行处于活跃状态时手动“触发运行(Trigger Run)”:Render会取消当前活跃运行,然后启动新的运行实例。
  • 新的Git构建/部署不会影响已在运行中的任务——正在执行的进程会持续使用启动时的代码版本,直到退出。
  • 基于Docker的cron:每次运行都会重新拉取镜像;不要假设像持续运行的容器那样,多次调用之间会复用镜像层或镜像。
  • 全UTC环境:文档中的cron表达式和“午夜”均指UTC时间。常见错误是直接复制本地时间计划到表达式中,未转换为UTC时间。

Cron vs Worker vs Workflow

Cron vs 工作者 vs 工作流

NeedUseWhy
Periodic task under 12hCron JobScheduled, simple, exits when done
Continuous job processingBackground WorkerAlways running, polls a queue
Periodic but over 12hBackground WorkerNo 12h cron run ceiling
Scheduled parallel computeCron Job + WorkflowCron triggers workflow runs on a schedule; workflows fan out or orchestrate parallel steps
需求选用方案原因
运行时长12小时以内的周期性任务Cron Job定时触发、配置简单、完成后自动退出
持续处理任务后台工作者(Background Worker)始终运行,轮询任务队列
周期性但运行时长超过12小时后台工作者(Background Worker)无cron的12小时运行时长上限
定时并行计算Cron Job + 工作流(Workflow)Cron定时触发工作流运行;工作流可实现任务分发或并行步骤编排

Blueprint Configuration

Blueprint配置

Cron services use
type: cron
with a
schedule
and the usual build/start and env wiring:
yaml
services:
  - type: cron
    name: nightly-cleanup
    schedule: "0 * * * *" # hourly at minute 0 — must be quoted in YAML
    buildCommand: pip install -r requirements.txt
    startCommand: python cleanup.py
    envVars:
      - key: DATABASE_URL
        fromDatabase:
          name: my-db
          property: connectionString
  • schedule
    : standard five-field cron (
    minute hour day-of-month month day-of-week
    ), UTC.
  • buildCommand
    /
    startCommand
    : same roles as other non-Docker services; Docker images use image + start command as configured for image-backed crons.
  • envVars
    : same patterns as web services and workers (secrets, linked databases, etc.).
YAML note: the
schedule
value must be quoted so characters like
*
are not parsed as YAML aliases or flow syntax.
Cron服务使用**
type: cron
,搭配
schedule
**以及常规的构建/启动命令和环境变量配置:
yaml
services:
  - type: cron
    name: nightly-cleanup
    schedule: "0 * * * *" # hourly at minute 0 — must be quoted in YAML
    buildCommand: pip install -r requirements.txt
    startCommand: python cleanup.py
    envVars:
      - key: DATABASE_URL
        fromDatabase:
          name: my-db
          property: connectionString
  • schedule
    :标准五段式cron表达式(
    分钟 小时 日期 月份 星期
    ),基于UTC时间。
  • buildCommand
    /
    startCommand
    :与其他非Docker服务作用相同;Docker镜像需配置镜像地址及启动命令,用于基于镜像的cron任务。
  • envVars
    :与Web服务和工作者的配置模式相同(包含密钥、关联数据库等)。
YAML注意事项:
schedule
的值必须加引号,避免
*
等字符被解析为YAML别名或流语法。

Common Patterns

常见应用场景

  • Database cleanup — archive or delete stale rows on a schedule
  • Report generation — build CSV/PDF and upload to object storage or email
  • External API sync — pull or push batches on an interval
  • Cache warming — hit endpoints or rebuild caches before peak traffic
  • Scheduled emails — digest or reminder sends driven by cron + mail/API
  • 数据库清理——按计划归档或删除过期数据行
  • 报表生成——生成CSV/PDF文件并上传至对象存储或通过邮件发送
  • 外部API同步——按间隔拉取或推送批量数据
  • 缓存预热——在流量高峰前访问端点或重建缓存
  • 定时邮件发送——通过cron搭配邮件/API驱动摘要或提醒邮件发送

References

参考资料

TopicFile
Expression examples, framework commands, errors, env vars
references/cron-patterns.md
Heroku Scheduler → Render mapping, blueprint example
references/migration-from-scheduler.md
主题文件
表达式示例、框架命令、错误排查、环境变量
references/cron-patterns.md
Heroku Scheduler → Render迁移指南、Blueprint示例
references/migration-from-scheduler.md

Related Skills

相关技能

  • render-deploy — First-time deploy, service creation, Dashboard flow
  • render-blueprints — Full
    render.yaml
    schema, previews, common mistakes
  • render-background-workers — Long-lived processes, queues, no 12h cap
  • render-workflows — Orchestrated and parallel jobs, often triggered on a schedule from cron
  • render-deploy — 首次部署、服务创建、控制台操作流程
  • render-blueprints — 完整
    render.yaml
    schema、预览功能、常见错误
  • render-background-workers — 长期运行进程、任务队列、无12小时时长限制
  • render-workflows — 编排式并行任务,通常由cron定时触发