There are many situations in which you want to schedule some code to run at a specific recurring interval. In Velo, you can create jobs and schedule them to run on an hourly, daily, weekly, or monthly basis using the Job Scheduler.
Some common uses of the Job Scheduler are to:
Scheduled Jobs run with Admin permissions.
To configure scheduled jobs, start by creating file in the backend root named jobs.config. The file must contain a JSON object that defines the jobs you want to schedule. You can configure up to twenty jobs.
A job's configuration defines when the job runs and what code it runs. A job can run any backend function defined in your site. Each job is represented by an object in the jobs
array.
Each job definition contains the following information:
functionLocation
: Path to the backend file in which the job function resides.
functionName
: Name of the function to run at the scheduled time.
description
: Optional job description.
executionConfig
: Configuration that defines when the job runs.
There are two mutually exclusive ways to define when the job runs:
dayOfWeek
or dateInMonth
properties.A few more things to keep in mind when scheduling jobs are:
Now that you know the rules, let's take a look at some examples of scheduled jobs.
Here you can see two scheduled jobs. The first job is scheduled using a cron expression and it sends a status report every Monday morning at 8:00 in the morning UTC time.
The second job is scheduled using the time
and dateOfMonth
properties and it deletes stale items from the site's database at one in the morning UTC time on the first day of every month.