Skip to main content

Move your scheduled jobs (cron jobs) to Nife

If your old platform ran a job on a schedule, such as a nightly report or a cleanup task, you can run it on Nife as a CronJob workload. This guide moves one scheduled job.

Before you start​

  • A Nife account and an organization.
  • The code or container image for the job.
  • For each job on your old platform: the schedule, what it runs, its environment variables and the time zone its schedule uses.

How scheduled jobs work on Nife​

  • A CronJob workload runs your app's container on a schedule.
  • The schedule is a cron expression with five fields: minute, hour, day of month, month and day of week. For example, 0 2 * * * runs every day at 2:00. The macros @hourly, @daily, @weekly, @monthly and @yearly also work. The @every form is not supported.
  • Times are in UTC unless you put a time zone in front of the expression, for example CRON_TZ=Asia/Kolkata 0 9 * * *. Use an IANA time zone name.
  • If you do not set a schedule, the job runs every hour.
  • A run that is still going after 12 hours is stopped.
  • Nife keeps the last 10 successful runs and the last 10 failed runs for each job.

Step 1: Note your current schedule​

  1. Write down the schedule for each job.
  2. Check which time zone your old platform used. Many use UTC. Convert if you need to.
  3. Write down the command the job runs and the environment variables it needs.

Step 2: Create the job on Nife​

In the dashboard:

  1. Open the Deploy Wizard and choose the CronJob workload type.
  2. Enter your cron expression, or pick one of the presets (every hour, every 6 hours, daily at midnight).
  3. Choose a time zone if you do not want UTC.
  4. Finish the deploy steps as you would for any app.

With nifectl:

nifectl init --workload-type cronjob --schedule "0 2 * * *"
nifectl deploy

nifectl saves the schedule in your nife.toml file as cron_schedule. To change it later, run nifectl deploy --schedule "0 3 * * *".

Step 3: Set your environment variables​

Add the variables the job needs. See Move your environment variables and secrets.

Step 4: Test​

  1. Set a short schedule first, such as every hour, or a time a few minutes from now.
  2. After the first run, check the output with nifectl logs.
  3. Set the schedule you really want.

Step 5: Switch over​

  1. When the Nife job has run correctly once, turn off the job on your old platform. This stops the job running in two places.
  2. Check the next scheduled run on Nife.

What this guide does not cover​

Retries after a failure, rules for overlapping runs, and alerts when a run fails. If you depend on these, contact Nife support at support@nife.io before you migrate, and we will help you plan it.

Troubleshooting​

  • Job never runs: check the schedule has five fields and the time zone name is valid.
  • Job runs at the wrong hour: the schedule is in UTC unless you set a time zone.
  • Job stops early: runs are stopped after 12 hours.

Need help? Email support@nife.io.