openartifacts.sh / templates / scheduled-job
Scheduled job
A job the platform runs on a schedule: every 15 minutes it fetches a URL and records the status, the time it took, the size and a hash of the body (so a change shows), and GET / lists the recent runs. Python with only the standard library. Swap the fetch for your own work and keep the plumbing.
Deploy it
One call publishes it as-is and boots it. It needs no environment variables. Files you send with the call replace the template's files of the same name, and fields you send override its oa.json. It is billed like any service.
With curl
# once: an account and its token
curl -sX POST "https://openartifacts.sh/v1/signup?ref=templates"
# the template, published and booted
curl -sX POST https://openartifacts.sh/v1/publish \
-H "Authorization: Bearer $OA_TOKEN" \
-F type=service -F template=scheduled-job -F slug=my-job
From an MCP client
publish_artifact {"type": "service", "template": "scheduled-job",
"slug": "my-job"}
With the CLI
npx @openartifacts/cli signup --ref templates # once
npx @openartifacts/cli deploy --template scheduled-job --slug my-job
# or edit first: the files, here, then a normal deploy
npx @openartifacts/cli init scheduled-job
npx @openartifacts/cli deploy ./scheduled-job --slug my-job
Then: It runs POST /tick every 15 minutes (UTC). Run it now with curl -X POST <url>/tick, then open <url>/ to see the run. Set TARGET_URL (oa env set my-job TARGET_URL=...) to check your own URL.
How the schedule works
The schedule is declared in oa.json:
{"type": "service", "start": "python3 job.py", "sleep_after_s": 60,
"schedules": [{"cron": "*/15 * * * *", "path": "/tick"}]}
cron is five fields, in UTC. At each tick the platform wakes the service and POSTs to path with an X-OA-Schedule header. The platform strips X-OA-* headers from every public request, so a request that carries one came from the scheduler. Edit the cron line and republish to change the schedule; add entries to run several paths.
Call it
curl -s -X POST <url>/tick # run it now, by hand (trigger "manual")
curl -s <url>/ # recent runs as JSON; a browser gets a table
curl -s "<url>/runs?limit=50"
Environment
| Variable | Required | What it does |
|---|---|---|
TARGET_URL | no | The URL each run fetches. Default https://example.com/. |
JOB_TOKEN | no | When set, a run started by hand needs Authorization: Bearer <JOB_TOKEN>. Scheduled runs never need it. |
KEEP_RUNS | no | How many runs to keep. Default 200. |
Set them with oa env set <slug> TARGET_URL=https://... or PUT /v1/artifacts/<slug>/env {"env":{"TARGET_URL":"https://..."}}.
Data
Runs are kept in /data/runs.json, a small file rewritten whole after every run (to a sibling, then renamed over the old one), so it survives sleeps, restarts and redeploys, and a crash mid-write leaves the previous list intact. Runs never overlap: a tick that arrives while one is running waits for it.
Extend it
- Do your own work: replace the body of
run_job()and return whatever you want recorded. A run that raises is recorded as failed, not lost. - Alert on a change or a failure:
record["changed"]andrecord["ok"]are there; POST to a chat webhook fromrun_job()when they say so. - Keep a run short (well under the 60-second idle window), or the next request waits for it.
What it costs
Prices for small, the size this template needs (current prices on openartifacts.sh):
- Asleep: no runtime charge between ticks. The bundle and
/dataare stored at $0.05 per GB-month. - Awake: $0.03 per awake hour, billed per minute, plus $0.216 per vCPU-hour of CPU actually used.
sleep_after_sis 60 here, so a short run keeps it awake about 65-70 seconds, billed as 2 minutes ($0.001): 96 ticks a day is about $0.10 a day, $2.88 a month, plus CPU. - Raising
sleep_after_sor ticking more often raises that: at the default 600 seconds, a 15-minute schedule would keep it awake two thirds of the day, and a schedule more frequent thansleep_after_skeeps it awake for good ($0.72 a day).
Starting it needs an hour of awake time in credit ($0.03), and an account runs one service per $1 of balance.
Files
README.md3.1 kBjob.py7.7 kBoa.json138 B
Every file, as JSON you can edit and publish: GET /v1/templates/scheduled-job.