Download the PHP package hutnikau/job-scheduler without Composer
On this page you can find all versions of the php package hutnikau/job-scheduler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hutnikau/job-scheduler
More information about hutnikau/job-scheduler
Files in hutnikau/job-scheduler
Package job-scheduler
Short Description PHP job scheduler
License MIT
Homepage https://github.com/hutnikau/job-scheduler
Informations about the package job-scheduler
job-scheduler
Job scheduler is a PHP library for scheduling time-based repetitive actions. It uses (RRULE) or Cron notation to configure time and recurrence rule of each job.
Goals
Sometimes amount of cron jobs becomes too large. The main goal is reduce amount of cron jobs to only one.
Installation
Via Composer
Usage
Create recurrence rule
iCalendar syntax
Cron syntax:
Get the recurrences between dates
Get the next recurrence after given date
Create a job
Job constructor have the following signature:
\Scheduler\Job\Job::__construct(RRule $rRule, callable $callable);
Example: iCalendar syntax
Cron syntax:
Note: Cron syntax does not allow to limit number of occurrences.
Create Job from string using iCalendar syntax:
Create Job from string using cron syntax:
Schedule a job
Scheduler constructor accepts array of jobs as first parameter:
Run scheduled jobs
Run all jobs scheduled from '2017-12-12 20:00:00' to '2017-12-12 20:10:00':
Note: the last
true
parameter means that jobs scheduled exactly atfrom
orto
time will be included. In this example it means that jobs scheduled to be run at '2017-12-12 20:00:00' or '2017-12-12 20:10:00' will be executed.
$jobRunner->run(...)
returns an array of reports (\Scheduler\Action\Report)
Workers
Worker is supposed to be run continuously and check with defined period if there are jobs to be executed.
Worker above will make two iterations (checks if there is a job to execute) with an interval of one minute. Default amount of iterations is 1000.
Action inspectors
In order to be able to run two or more workers on different servers or to avoid execution of one job twice action inspectors may be used:
Currently there is also Rds implementation so all the performed actions data can be stored in SQL storage.
Constructor of expects to receive \Doctrine\DBAL\Connection
instance:
Note: Make sure you prepared the database (created the table) using initDb static method:
Reports
\Scheduler\Action\Report
class synopsis:
In case if during execution an exception has been thrown then this exception will be returned as a result of action.
$report->getType()
returns one of two values: \Scheduler\Action\Report::TYPE_SUCCESS | \Scheduler\Action\Report::TYPE_ERROR
Warnings
- Be careful with timezones. Make sure that you create
\DateTime
instances with correct timezone. - Accuracy of scheduler up to seconds. You must be accurate with
$from
,$to
parameters passed to the runner to not miss an action or not launch an action twice (alternatively use action inspectors). - Use
\Scheduler\Job\CronRule
implementation in case if number of occurrences is not limited. \Scheduler\Job\RRule
implementation is more flexible but in case of large or unlimited number of repeats there may be performance issues. By default limit of\Scheduler\Job\RRule
implementation is 732 repeats. More information: https://github.com/simshaun/recurr
Testing
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- This library was created by Aleh Hutnikau
License
The MIT License (MIT). Please see License File for more information.
All versions of job-scheduler with dependencies
simshaun/recurr Version ~3.0.0
mtdowling/cron-expression Version ~1.2.0
jeremeamia/superclosure Version ^2.0
doctrine/dbal Version ~2.5