All posts
Joe Connolly workers, cron jobs, migrations, procfile

Workers, cron jobs and migrations in one app

Run background workers, scheduled jobs and database migrations from the same Procfile as your web app, in one deploy. Cron jobs bill per second.

Workers, cron jobs and migrations in one app

Most apps that last a few months grow the same three extra parts: something that works through a queue, something that runs at three in the morning, and a migration that has to happen before the new code takes traffic.

Until today, velixir's answer to all three was "run another app". It worked, but it meant three deploys to keep in step, three sets of environment variables, and migrations squeezed into the start command, where every replica races to run them at once.

Now they live in the same app. If you have a Procfile, it already works:


web: npm start
worker: node worker.js
release: npx prisma migrate deploy

Every line other than web is a worker. release runs once per deploy. For schedules, add velixir.json:

{
  "cron": [
    { "name": "digest", "schedule": "0 8 * * *", "command": "node digest.js" }
  ]
}

What happens if a migration fails?

Nothing changes. The release command runs on the new build before anything about the running app moves. If it exits non-zero, the deploy stops, the old release keeps serving, and you see the last lines of output on the deploy. It runs once, so two replicas never race to apply the same migration.

How much does a cron job cost?

Only the seconds it runs. A job that takes 20 seconds every 15 minutes on Starter runs for about 16 hours a month, which comes to around €0.15. Keeping a Starter worker running all month just to fire a timer costs €6.95.

Can I scale a worker on its own?

Yes. Set replicas and size per worker on the Processes tab, or run velixir ps:scale worker=2. Your number sticks: a redeploy never resets it.

Workers and cron jobs need a paid plan. The release command runs on every plan, Free included. The pricing page has the rates and a calculator, and the processes docs have the details.


Got an app to ship? velixir hosts it in any language, on servers in the EU.

Start free - your first month's on us