OpenArtifacts

openartifacts.sh / templates / scheduled-job

Scheduled job

Python 3.11, standard library · size small · 3 files, 10.9 kB

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

VariableRequiredWhat it does
TARGET_URLnoThe URL each run fetches. Default https://example.com/.
JOB_TOKENnoWhen set, a run started by hand needs Authorization: Bearer <JOB_TOKEN>. Scheduled runs never need it.
KEEP_RUNSnoHow 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

What it costs

Prices for small, the size this template needs (current prices on openartifacts.sh):

Starting it needs an hour of awake time in credit ($0.03), and an account runs one service per $1 of balance.

Files

Every file, as JSON you can edit and publish: GET /v1/templates/scheduled-job.


← all templates · openartifacts.sh · docs.md · skill.md