Cron jobs on a PaaS: how to run scheduled tasks
THE SHORT ANSWER
A PaaS without a cron service runs scheduled jobs in one of two ways: a scheduler inside a process that never stops, or an outside scheduler that calls a protected URL in your app. EthioDeploy has no cron service type, so you run APScheduler, node-cron, Celery beat, Laravel's schedule:work or Solid Queue in a Background Worker, or call an endpoint from a scheduled GitHub Actions workflow. A scheduler inside a Free web app misses its jobs while the app sleeps, which happens after 30 minutes without traffic. Background Workers don't sleep, and on Pro and Business nothing sleeps.
Why a crontab doesn't work on a PaaS
On a server you own, the cron daemon reads your crontab and starts each command on time. A PaaS runs your app in a container that starts one process, your start command, and nothing else. No cron daemon runs in it, and every deploy replaces the container, so a crontab line has nothing to read it.
Some platforms add a cron service type that starts a container on a schedule. Without one, you have two options:
- Run a scheduler inside a process that stays up: a library that keeps the schedule in memory and calls your function when it's due.
- Let something outside call your app on a schedule. A scheduled GitHub Actions workflow sends an HTTP request to a protected route, and the route does the job.
EthioDeploy has no cron service type. Every project or service is either a Web Service or a Background Worker, so scheduled jobs use one of the two options above.
Which process keeps a schedule firing?
An in-process scheduler only runs while its process runs. On EthioDeploy that depends on the plan and on the kind of process:
| Where the scheduler runs | Does it fire on time? |
|---|---|
| Free web service | Only while the app is awake. It sleeps after 30 minutes without traffic, and jobs due while it sleeps are skipped. |
| Free Background Worker | Yes. Workers don't sleep. Memory and CPU count against the Free plan's monthly quota of 50 GB-hours and 20 CPU-hours. Free has one project, so this project has no web service. |
| Pro or Business web service | Yes, it never sleeps. It can run twice, though: see the next paragraph. |
| Pro or Business worker service | Yes. This is the setup we recommend: a separate service from the same repo that runs only the scheduler. |
Putting the scheduler in the web process has two problems even when the app never sleeps. Servers like gunicorn and PM2 cluster mode start several copies of your app, and each copy starts its own scheduler. And a web deploy starts the new container while the old one still serves traffic, so for a short time two schedulers run. A Background Worker deploy stops the old process before it starts the new one, so only one copy runs at a time.
On Pro and Business, add the scheduler as a service: open the project's Services tab, click Add service, pick Background worker and set its start command. It runs from the same repo with the same env vars and databases. From the CLI:
ethiodeploy services add scheduler --start "python scheduler.py"
Services have no pull request previews, so a preview deploy never runs your jobs a second time against the production database.
Python: APScheduler or Celery beat
For a few jobs and no task queue, APScheduler in its own script is the simplest choice. Pin version 3: the 4.x releases are still pre-releases with a different API. BlockingScheduler is the one to use when the scheduler is the only thing the process does:
# requirements.txt: APScheduler>=3.11,<4
import logging
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.triggers.cron import CronTrigger
logging.basicConfig(level=logging.INFO)
sched = BlockingScheduler(timezone="UTC")
@sched.scheduled_job(CronTrigger.from_crontab("*/15 * * * *", timezone="UTC"))
def clean_expired_sessions():
... # your job
sched.start()Deploy it as a Background Worker with the start command python scheduler.py. In a Django project, call django.setup() at the top of the script (after setting DJANGO_SETTINGS_MODULE) before importing models, or write the job as a management command.
APScheduler's FAQ warns against starting it inside a web app that runs several worker processes: each process gets its own scheduler and the jobs run more than once. Its own advice is to run the scheduler in a dedicated process.
If the app already uses Celery, use Celery beat. Beat only sends tasks to the queue and a Celery worker runs them, so you need both processes and a broker. Celery's docs say to run only one beat at a time, or tasks are sent twice. The Django + Celery + Redis guide covers the worker, beat and Redis setup on EthioDeploy.
Node.js: node-cron
node-cron takes a crontab expression, with an optional sixth field for seconds. Version 4 starts a task as soon as you schedule it. noOverlap skips a run while the previous one is still going:
// scheduler.js (npm install node-cron)
import cron from "node-cron";
import { cleanExpiredSessions } from "./jobs.js";
cron.schedule(
"*/15 * * * *",
async () => {
await cleanExpiredSessions();
},
{ timezone: "UTC", noOverlap: true },
);Run it as a Background Worker with node scheduler.js. The timer keeps the process alive, so the file needs nothing else. NestJS apps that use @nestjs/schedule have the same sleep and duplicate problems as any scheduler in a web process: on Free, the @Cron() jobs stop while the app sleeps.
Laravel and Rails
Laravel defines the schedule in routes/console.php. Laravel's docs run it with a cron entry that calls schedule:run every minute. Without cron, php artisan schedule:work does the same job: it stays in the foreground and runs the scheduler every minute. Use it as the start command of a worker service:
ethiodeploy services add scheduler --start "php artisan schedule:work"
Add ->withoutOverlapping() to jobs that can run longer than their interval. ->onOneServer() only matters when more than one scheduler runs, and it needs a cache all of them share, such as Redis. More on queues and the scheduler in the Laravel guide.
Rails 8 apps with Solid Queue list recurring jobs in config/recurring.yml. The scheduler runs inside bin/jobs, so a worker service with the start command bin/jobs runs both your queued jobs and the recurring ones. See the Rails guide.
An outside trigger: GitHub Actions calling a protected URL
This keeps the job code in your web app and moves only the clock outside. It is also the one way to run a job on time from a Free web app, because the request wakes the app. Add a route that does the job and only accepts a secret:
import { timingSafeEqual } from "node:crypto";
// Express. CRON_SECRET is an env var on the app and a secret in GitHub.
app.post("/internal/cron/cleanup", async (req, res) => {
const expected = Buffer.from(`Bearer ${process.env.CRON_SECRET}`);
const got = Buffer.from(req.get("authorization") ?? "");
if (got.length !== expected.length || !timingSafeEqual(got, expected)) {
return res.sendStatus(401);
}
await cleanExpiredSessions();
res.sendStatus(204);
});Then call it from .github/workflows/cleanup.yml:
name: cleanup
on:
schedule:
- cron: "0 3 * * *"
workflow_dispatch:
jobs:
call:
runs-on: ubuntu-latest
steps:
- name: Call the cleanup route
env:
CRON_SECRET: ${{ secrets.CRON_SECRET }}
run: |
curl -fsS --max-time 120 --retry 2 -X POST \
-H "Authorization: Bearer $CRON_SECRET" \
https://<project-slug>.ethiodeploy.app/internal/cron/cleanupThe long --max-time is for a Free app that is asleep: the request waits up to 30 seconds while the app boots, then for the job itself. workflow_dispatch adds a button to run it by hand.
What GitHub's docs say about scheduled workflows:
- The shortest interval is once every 5 minutes.
- Runs can be delayed when GitHub Actions is busy, and under enough load some are dropped. Don't use it for jobs that must run at an exact minute.
- Times are UTC unless you add a
timezonekey with an IANA name next tocron. - It runs the workflow file on the latest commit of the default branch.
- In a public repo, scheduled workflows are turned off after 60 days without repository activity.
- Standard runners are free in public repos. In a private repo, each run uses your account's Actions allowance, which adds up for a job every few minutes.
Make jobs safe to run twice, or to miss
Whatever runs the clock, a job will sometimes run twice or not at all: a deploy at the wrong second, a crash, a delayed GitHub run. Write jobs so that either is harmless:
- Work from the database, not from the clock. “Send reminders that are due and not yet sent” catches up after a missed run; “send reminders for 9:00” doesn't.
- Mark work done in the same transaction that does it, so a second run finds nothing left.
- When two copies might start together, take a lock first. In Postgres,
SELECT pg_try_advisory_lock(42)returns false for everyone but the first caller. - Keep long jobs short or resumable. A deploy stops the old container with SIGTERM and kills it 10 seconds later if it hasn't exited.
Questions
There is no cron service type. Run a scheduler such as APScheduler, node-cron, Celery beat, Laravel's schedule:work or Solid Queue inside a Background Worker, or have a scheduled GitHub Actions workflow call a protected route in your app.
Yes, two ways. Make the project a Background Worker that runs a scheduler: workers don't sleep, and they count against the Free plan's 50 GB-hours a month. Or keep a web app and call a protected route from a GitHub Actions schedule; the request wakes the app if it's asleep. A scheduler inside a Free web app skips jobs while the app sleeps.
On a PaaS the usual causes are: the process running the scheduler was asleep or restarting at that moment, the job ran in a different timezone than you expected (most schedulers and GitHub Actions default to UTC), or a scheduled GitHub workflow was delayed, dropped, or disabled after 60 days without activity in a public repo.
More than one scheduler is running. Common causes: the scheduler starts inside each gunicorn or PM2 worker process, two Celery beat processes run at once, or a web deploy briefly runs the old and new containers together. Run the scheduler in one dedicated worker process and take a lock in the job.
You can install cron in the image, but the container only runs your start command, so cron has to be that command or be started by it. Then the container is a scheduler, not a web app. A scheduler library in a Background Worker does the same with less setup.
Sources
Checked on November 29, 2026:
Push a repo. Get a URL.
- Web services and background workers
- Deploy Django with Celery and Redis
- Deploy a Laravel app
- Pricing and plan limits
Join the EthioDeploy Telegram
Release notes as they ship, plus deploy help from the team and other developers.