Scheduled Jobs
FEAST includes the ability to run scheduled jobs without having to manage a system scheduler/cron task (besides the scheduled runner). This utility provides a very powerful and flexible way to run re-occuring tasks.
To enable the Job runner, add feast:job:run-cron to your system's task scheduler to run every minute.
On Linux, add the following to your crontab, replacing [project_root]
with the path to your project. (with crontab -e
)
* * * * * cd [project_root] && php famine feast:job:run-cron >> /dev/null 2>&1
Creating a Scheduled Job
To create a scheduled job, first extend the Feast\Jobs\CronJob
class. You may override any of the properties directly
if you do not need flexible scheduling, or you may use the long list of helper methods below.
Once you have created your job class, you may add it to scheduled_jobs.php
. Some samples are included commented out to
assist you.
Your job class must contain a run
method. This method is called when all the scheduling criteria is met.
Scheduling
Environmental criteria
-
environment
- This method sets the environment to run on. If not called or overridden, defaults to production. -
withoutOverlapping
- This method prevents the job from running concurrently to the same job. It takes an optional timeout parameter. The default timeout for being considered as "running" is 1440 minutes (or 1 full day). -
when
- This method takes a criteria expression that evaluates to either true or false. If this evaluates to false, the job will not run. -
evenInMaintenanceMode
- If this method is not called andrunInMaintenanceMode
is not true, then when the Application is in maintenance mode, the job will not run. -
timezone
- Specify the timezone for all cron rules to be compared against. -
runInBackground
- If this method is called and you are on a Linux/Unix system, the job will run in the background. Otherwise, all scheduled jobs for the current minute will run sequentially.
Time criteria
The methods in the time criteria are mostly self-explanatory, but more details are provided below when needed. The criteria baseline defaults to every minute. Time criteria methods may be chained for more granularity.
-
cron
- Takes a cron string as an argument.
Minute based
everyMinute
everyOddMinute
-
everyTwoMinutes
- Opposite of everyOddMinute everyThreeMinutes
everyFourMinutes
everyFiveMinutes
everyTenMinutes
everyFifteenMinutes
everyTwentyMinutes
everyThirtyMinutes
Hour based
-
hourly
- Every hour on the hour (unless the minute has been set already) -
hourlyAt
- Takes a minute parameter. Runs every hour at that minute only. hourlyOnOddHours
everyTwoHours
everyThreeHours
everyFourHours
everySixHours
everyEightHours
everyTwelveHours
Day based
-
daily
- Once a day. Defaults to 0:00 (or 12:00am) unless the hour or minute have been set already. -
dailyAt
- Once a day at the specified time (24-hour format. Example: 23:45). -
twiceDaily
- Twice a day at the specified hours (on the hour, unless the minute has been explicitly set)
Week based
-
weekly
- Once a week on Sunday. Defaults to 0:00 (or 12:00am) unless the hour or minute have been set already. -
weeklyOn
- Once a week on the specified day (0 and 7 = Sunday, 6 = Saturday) at an optional specified time (24-hour format. Example: 23:45).
Day of week based
weekdays
weekends
sundays
mondays
tuesdays
wednesdays
thursdays
fridays
saturdays
-
days
- This method takes an array of numbers 0-7. 0 and 7 are Sunday, 6 = Saturday.
Month based
-
monthly
- Once a month on the first of the month. Defaults to 0:00 (or 12:00am) unless the hour or minute have been set already. -
monthlyOn
- Once a month on the specified day of the month at an optional specified time (24-hour format. Example: 23:45). Note: if the chosen day does not exist in the current month, it will be skipped. -
twiceMonthly
- Twice a month on the specified days at an optional specified time (24-hour format. Example: 23:45).
Large Format
-
quarterly
- Once per quarter (Jan, April, Jul, and October) on the 1st of the month at Midnight. If the day of the month, hour, or day have been set, the chosen values are kept. -
yearly
- Once per year in January. Defaults to the 1st at midnight. If the day of the month, hour, or day have been set, the chosen values are kept. -
yearlyOn
- Once per year on the specified day of the specified month (at an optional time). Defaults to 0:00 (or 12:00am) unless the hour or minute have been set already.
Time filters
-
between
- Takes a start and end time inhour:minute
format. The job will not run if the current time is not within this range. -
unlessBetween
- Takes a start and end time inhour:minute
format. The job will not run if the current time is within this range.
Powered by FEAST Framework
See this project at https://github.com/feastframework/documentation