Workers and scheduled jobs
An app can run background workers beside its web server, such as a queue consumer, and commands on a schedule, such as a nightly cleanup. Both run from the app's live release, with its keys and its database's DATABASE_URL, and write into the app's logs.
Background workers
A worker is a long-running process with no port. List it in the app's Procfile, one line each, as on Render or Heroku:
web: npm start worker: node worker.js mailer: node mailer.js
Every line other than web: and release: is a worker. Publish the app and each worker starts with it.
- Up to 4 workers. A name is letters, digits,
-and_, up to 20 characters. - One of each worker runs, however many copies the app has.
- Workers don't see the app's
/datafolder: they share data through the app's database. - A publish waits until each worker has run for 10 seconds. A worker that stops before that keeps the new release from going live: the release that was live stays live, and the publish ends with the worker's last log lines.
- Workers stop and start with the app: on a publish, offline and online, undo, and a change of keys or size.
secretbase statusshows each worker as running or stopped, for exampleWorkers: worker running. On the dashboard: the app's Workers row.
Scheduled jobs
List them in secretbase.json at the app's root:
{
"jobs": [
{"name": "cleanup", "schedule": "0 3 * * *", "command": "node cleanup.js"},
{"name": "report", "schedule": "@hourly", "command": "npm run report"}
]
}
- Up to 10 jobs. A name follows a worker's rules.
scheduleis the five cron fields, in UTC: minute, hour, day of the month, month, day of the week, with*, lists, ranges and steps (*/15).@hourly,@dailyand@weeklywork too; seconds don't.commandruns in the app's first copy, with its keys and limits.- A job runs only while the app is online. A run still going at its next time is skipped (the logs say so), and a run is stopped after 1 hour. A job that fails never takes the app offline.
- A job that isn't valid stops the publish: "secretbase.json's job <what> isn't valid: <why>. Nothing was published."
Each job with its schedule, its next run and its last run with its exit code:
$ secretbase jobs
On the dashboard, the app page lists them too.
Logs
A worker's lines start with [<worker>] and a job's with [job <name>] . Each job run ends with a line such as [job cleanup] finished in 2s, exit 0.
$ secretbase logs --tail 50
From a laptop
Add --to <server> to jobs and logs, with a token for that app (Connect from a laptop):
$ secretbase jobs my-app --to server $ secretbase logs my-app --tail 50 --to server
A command to run once before each release goes live, such as a database migration, is a release: line: see Databases.