Scheduled Jobs
A scheduled job is a command that runs at regular intervals based on a
predefined schedule. The command of the scheduled job has access to the same
environment and binaries as the app runtime. It can either be specified on
creation of the app or later using the update
command.
Specifying a scheduled job on app creation
You can specify a scheduled job when creating an application by using various
scheduled job related flags on the nctl create app
command.
--scheduled-job-command="bundle exec rails runner" Command to execute to start the scheduled job.
--scheduled-job-name=scheduled-1 Name of the scheduled job job to add.
--scheduled-job-size=micro Size (resources) of the scheduled job (defaults to "micro").
--scheduled-job-schedule="* * * * *" Cron notation string for the scheduled job (defaults to "* * * * *").
$ nctl create app --scheduled-job-command="sleep 5; date" --scheduled-job-name="myjob-1"
The scheduled job will run depeding on the schedulde parameter. The parameter is given in cron notation. You can use (this website)[https://crontab.guru/] to easier understand your schedule.
If the scheduled job takes longer than the defined interval, the next execution will be skipped. Running scheduled jobs will not be interrupted.
Specifying a scheduled job on other configuration layers
As scheduled jobs are part of the configuration of a Deploio application, you can
also specify them on other configuration layers. For
example, you can specify a scheduled job via the git configuration source file
.deploio.yaml
:
scheduledJobs:
- command: sleep 60; date
name: scheduled-1
retries: 0
schedule: "*/5 * * * *"
size: micro
timeout: 5m0s
Updating and deleting scheduled jobs
You can use the same parameters as above with nctl to update your scheduled job:
--scheduled-job-command="bundle exec rails runner" Command to execute to start the scheduled job.
--scheduled-job-name=scheduled-1 Name of the scheduled job job to add.
--scheduled-job-size=micro Size (resources) of the scheduled job (defaults to "micro").
--scheduled-job-schedule="* * * * *" Cron notation string for the scheduled job (defaults to "* * * * *").
$ nctl update app --scheduled-job-command="sleep 50; date" --scheduled-job-name="myjob-1"
To delete a scheduled job, you can also use the update command:
--delete-scheduled-job=DELETE-SCHEDULED-JOB Delete a scheduled job by name
$ nctl update app --delete-scheduled-job="myjob-1"
Viewing the status of a scheduled job
If a scheduled job fails, the associated release will NOT be set to failed and continue running. To see the detailed status of a scheduled job you can get the full release:
$ nctl get releases brave-scrambler-vc78b -o yaml
[...]
status:
atProvider:
scheduledJobStatus:
- name: scheduled-1
replicaObservation:
- replicaName: go-scheduled-scheduled-1-29038220
status: succeeded
At the bottom of the release you can see the status and it will show in detail
the status of the scheduled job. In addition to the status, the scheduled job's
log will be written to the normal app log and can be accessed using the nctl logs app
command.