Schedule Cron Jobs with Terminus
Schedule and automate specific tasks or jobs.
The Terminus Scheduled Jobs Plugin allows customers to schedule and automate specific cron jobs according to their requirements. You can specify the desired frequency (e.g., daily, weekly, monthly, hourly), and the actions to be performed. The system then executes the scheduled jobs automatically based on the provided instructions.
Requirements
Installation
To install this plugin, run the following:
For more information about installing Terminus Plugins, see Install Plugins in our Terminus Guide.
Schedules and Jobs
The plugin uses two distinct concepts:
-
Schedule: the definition of a recurring task — its name, the command to run, and the cron expression that determines frequency. Each schedule has a unique
<schedule_ID>. Commands that manage schedules (schedule:create,schedule:pause,schedule:resume,schedule:delete) require a<schedule_ID>. -
Job: a single execution of a schedule. Each time a schedule fires, it produces a job with its own
<job_ID>. Commands that inspect executions (job:list,job:logs) require a<job_ID>.
Use terminus scheduledjobs:schedule:list <site>.<env> to retrieve schedule IDs, and terminus scheduledjobs:job:list <site>.<env> to retrieve job IDs.
Usage
To create a new scheduled job:
Where:
-
<site>.<env>: the site name or UUID. Useterminus site:listto retrieve a list of site names and UUIDs. -
<job_name>: a brief description of the job. -
<cron_command>: the cron command you are scheduling. The following commands cannot be used:- Outbound email via
sendmailorlocalhostSMTP is not permitted. Email can still be sent via integrations with third party email providers either via their SMTP servers or API integrations. - New Relic
- Outbound email via
-
<cron_schedule>: the schedule for the job. See this Wikipedia page for more information about cron schedules.
Job Schedules
Job schedules are characterized as job definitions which allow setting a name for each job, a command and schedule in the UNIX cron format.
Jobs "Budget"
Each site has a fixed allocated budget of 300 minutes per day. This is calculated as the sum of all job durations, from the moment the job has started until it finished.
There are currently no restrictions around the number of schedules that can be created for any given site. If the daily budget is exhausted, running jobs are given a 15 minute grace period after which a timeout signal will be issued. No other jobs will be created that day until midnight UTC when all budgets are reset. In calculating the budget, partial minutes are rounded up.
Job Timeouts
Timeouts are dynamic and dependent on the remaining budget plus the 15 minute grace period. For instance, the daily available budget at the start of the day is 300 minutes, which means the first job's timeout is 315 minutes. When a job is launched throughout the day and the remaining budget is 60 minutes, the timeout will be calculated to 75 minutes.
Commands
For a full list of available commands, see the Terminus Scheduled Jobs Plugin documentation.