Scheduling
Description
The Automation Framework uses the Crunz scheduling system. Any file that ends in “Tasks” in /APP_BASE_PATH/tasks will be executed as a CRON.
Sample
/fintech/tasks/ispLoggingTasks.php
<?php
require_once __DIR__ . "/../bootstrap/app.php";
use Crunz\Schedule;
$schedule = new Schedule();
$x = "test";
$task = $schedule->run(function () use ($x) {
isp_log("This is a $x coming from the Scheduler");
});
$task
->everyHour()
->description("Test script to demonstrate easy scheduled task management.");
return $schedule;
Intervals
Dynamic Methods
Dynamic methods give us a wide variety of frequency options on the fly. We just need to follow this pattern:
every[NumberInCamelCaseWords]Minute|Hour|Day|Months?
As we can see, the method should start with the word every
, followed by a number in camel-case words, ending with one of these units of time: minute, hour, day, and month.
The s
at the end is optional and it’s just used for grammar’s sake.
With that said, the following methods are valid:
everyFiveMinutes()
everyMinute()
everyTwelveHours()
everyMonth
everySixMonths()
everyFifteenDays()
everyFiveHundredThirtySevenMinutes()
everyThreeThousandAndFiveHundredFiftyNineMinutes()
- …
This is how it is used in a task file:
<?php
// ...
$task = $schedule->run('/usr/bin/php email.php');
$task->everyTenDays();
$task = $schedule->run('/usr/bin/php some_other_stuff.php');
$task->everyThirteenMinutes();
// ...
return $schedule;
Running Events at Certain Times
To schedule one-off tasks, you may use on()
method like this:
<?php
// ...
$task = $schedule->run('/usr/bin/php email.php');
$task->on('13:30 2016-03-01');
// ...