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
- Write down the schedule for each job.
- Check which time zone your old platform used. Many use UTC. Convert if you need to.
- Write down the command the job runs and the environment variables it needs.
Step 2: Create the job on Nife
In the dashboard:
- Open the Deploy Wizard and choose the CronJob workload type.
- Enter your cron expression, or pick one of the presets (every hour, every 6 hours, daily at midnight).
- Choose a time zone if you do not want UTC.
- 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
- Set a short schedule first, such as every hour, or a time a few minutes from now.
- After the first run, check the output with
nifectl logs. - Set the schedule you really want.
Step 5: Switch over
- When the Nife job has run correctly once, turn off the job on your old platform. This stops the job running in two places.
- 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.