Skip to main content

Cronjobs

There are some scripts and processes that support applications that don't serve traffic and aren't intended to be run as persistent services. Sometimes developers might need to execute these tasks manually at their discression, and sometimes they might want them to be run on a schedule.

By defining task definitions inside Architect components, developers can make use of all the same service discovery and security benefits afforded to persistent services - making it much easier and safer to execute tasks.

services:
api:
# ...

cronjobs:
run-reports:
# run every sunday at 3am
schedule: 0 3 * * 0
image: my-image:latest
command: node run-reports.js
environment:
API_ADDR: ${{ services.api.url }}

The example above will schedule the run-reports task to be run every sunday at 3am. The task will have full access to the api service due to the injection of the service address in the API_ADDR environment variable.

Configuration options

Cronjobs support almost all of the same configuration options as deployments, but services cannot target cronjobs like they can deployments. Cronjobs aren't persistent services which means they can't respond to incoming API requests reliably.

The only field unique to cronjobs is the schedule field. This field is a cron string indicating the schedule at which the task will run. Architect will ensure the cronjobs are instrumented correctly regardless of where the task is deployed.