Docs/Data & jobs/Cron jobs

Cron jobs

4 min read
On this page

A cron job runs a shell command against one of your projects on a cron schedule. Dokwe runs the command where your app is deployed and records the output of each run.

Create a cron job#

  1. Open the form#

    Open Cron jobs and start a new job.

  2. Pick a project and name the job#

    Choose the project the command belongs to, then give the job a name (2–120 characters).

  3. Enter the command#

    The command runs with sh -c, so you can use pipes and &&. For example:

    bash
    node scripts/cleanup.js

    Commands can be up to 2,000 characters.

  4. Set the schedule#

    Enter a cron expression or pick a preset. See Schedule syntax.

  5. Choose a server (optional)#

    Leave Auto: primary env selected, or pin the job to a specific server. See Pin a job to a server.

  6. Create the job#

    Choose Create cron job. Active jobs are scheduled right away.

Schedule syntax#

Schedules use the standard five fields:

text
minute hour day-of-month month day-of-week
ExpressionRuns
* * * * *Every minute
*/5 * * * *Every 5 minutes
0 * * * *Every hour
0 2 * * *Every day at 02:00
0 9 * * 1-5Weekdays at 09:00
0 9-17 * * 1-5Every hour from 09:00 to 17:00 on weekdays
0 0 * * 1Every Monday at 00:00

Day of week runs from 0 (Sunday) to 6 (Saturday). Dokwe checks the expression when you create or edit a job and rejects invalid ones. The job page shows the next run time.

There is no time zone setting for each job. The dashboard presets describe their times in UTC.

Limit when a job runs#

Set Starts at and/or Ends at to give the job a time window. Runs before the start time are skipped. After the end time passes, the job's status changes to ended and it stops firing. The start must be before the end.

Where the command runs#

Dokwe picks the target from your project's latest live deployment:

  • Container apps: the command runs with docker exec in the app container, named fd-<environment-slug>.
  • Native apps on your own server: the command runs as the deploy owner set in your manifest, from the current folder under the deploy destination (<destination>/current). Dokwe doesn't use Docker for these. See Container or native.
  • No connected server: the command runs in the app's container on the Dokwe platform host.

Each run has a 5-minute timeout.

Pin a job to a server#

By default, a job fires on the server behind your primary environment: production if it has a server, otherwise the first environment that has one. To spread work across servers, choose a specific server in the Server field instead.

You can pin a job to any server attached to the project, either as an environment's server or as an enabled replica. If you pick one that isn't attached, you'll see: "Pinned server is not attached to this project. Add the server to an environment first, then retry." If a pinned server is later removed, the job falls back to the automatic choice.

Pinning changes the server only. The container name and native folder still come from the live deployment, so the app must run on the server you pick. See Replicas and routing.

Run, pause, and edit#

From a job's page you can:

  • Run now to fire the job right away.
  • Pause and Resume the schedule.
  • Change the name, command, schedule, time window, or server pin.
  • Delete the job.

Run history and errors#

Each job keeps a history of runs with the status (running, success, or failed), output, duration, and the server it ran on. The job list shows the last run time and result.

A run fails when the command exits with a non-zero code, wherever it runs. In that case the output starts with the exit code and context to help you find the problem:

text
[exit 1] env=my-app server=<server-id> mode=container
  container fd-my-app not found. Running fd-* on this host: fd-my-app-staging

Other common failures:

  • Container fd-<slug> not found or not running: the app container on the Dokwe platform host isn't running. Redeploy the app.
  • Target server agent is offline (<server-id>): cron skipped: the agent on the target server isn't connected. See Bring your own server.
  • Command timed out after 5 minutes: the command took longer than the timeout.

Failure emails#

When a run fails, Dokwe emails your workspace's alert addresses, or its owner and admins if it has none. You get at most one email a day about the same job while it keeps failing; the next one says how many more times it failed. Runs are limited to 5 minutes and aren't retried.

Cron jobs from dokwe.yml#

If your dokwe.yml declares cron entries, the agent writes them to the server's crontab. Dokwe finds them and lists them alongside the jobs you create in the dashboard, and you can pause or resume them there. See dokwe.yml.