oat-sa / extension-tao-scheduler
TAO job scheduler
Installs: 19 253
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 46
Forks: 0
Open Issues: 1
Type:tao-extension
Requires
- hutnikau/job-scheduler: ~0.6.1
- oat-sa/generis: >=15.22
- oat-sa/oatbox-extension-installer: ~1.1||dev-master
- oat-sa/tao-core: >=50.24.6
- dev-master
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.3.0
- v2.2.0
- v2.1.2
- v2.1.1
- v2.0.1
- v2.0.0
- v1.1.0
- v1.0.1
- v0.9.0
- v0.8.2
- v0.8.1
- v0.7.0
- v0.5.2
- v0.5.1
- v0.3.1
- dev-feature/sonarqube-integration
- dev-develop
- dev-fix/update-autoRelease-action-with-bot-user
- dev-feature/AUT-2995
- dev-feature/poc-php80-compatibility
- dev-feature/configurable_jobs
- dev-feature/declarative_jobs
- dev-remove-jenkinsfile
- dev-fix/bumpVersion
- dev-feature/CI_checks_test
- dev-experiment/changelog
This package is auto-updated.
Last update: 2024-11-16 16:34:29 UTC
README
RRULE standard is used to configure time and recurrence rule of each job.
Install
$ composer require oat-sa/extension-tao-scheduler
Usage
attach a job:
use oat\taoScheduler\model\scheduler\SchedulerServiceInterface;
$schedulerService = $this->getServiceManager()->get(SchedulerServiceInterface::SERVICE_ID);
$schedulerService->attach(
'FREQ=MONTHLY;COUNT=5', //Reccurrence rule (repeat monthly, 5 times)
new \DateTime('2017-12-12 20:00:00'), //Start date (time of first execution)
['taoExtension/ServiceName', 'methodName'] //Callback to be called.
);
Also cron notation may be used:
$schedulerService->attach(
'* * * * *', //Reccurrence rule (repeat minutely)
new \DateTime('2017-12-12 20:00:00'), //Start date (time of first execution)
['taoExtension/ServiceName', 'methodName'] //Callback to be called.
);
Note:
You can use any instance of callable type as callback except functions. In case if object is used ([$object, 'method']) make sure that object is instance of
PhpSerializable
.
Class name ofoat\oatbox\action\Action
instance may be used as a callback
detach a job:
use oat\taoScheduler\model\scheduler\SchedulerServiceInterface;
$schedulerService = $this->getServiceManager()->get(SchedulerServiceInterface::SERVICE_ID);
$schedulerService->detach(
'FREQ=MONTHLY;COUNT=5', //Reccurrence rule (repeat monthly, 5 times)
new \DateTime('2017-12-12 20:00:00'), //Start date (time of first execution)
['taoExtension/ServiceName', 'methodName'] //Callback to be called.
);
All given parameters to detach
function should be the same as in existing job.
Run JobRunner
sudo -u www-data php index.php '\oat\taoScheduler\scripts\JobRunner' 1518006301 PT10S
- First parameter is a timestamp from which scheduler should start to look up scheduled tasks. All the tasks scheduled before this time will be ignored.
Note:
Scheduled tasks may be executed even if their start date is later than timestamp given to job runner because they may be recurred and their start date is just a time of the first occurrence
If this parameter is omitted or less than 0 then start time will be taken from the storage (time of last seeking of scheduled job or time of last job runner iteration).
If there is no last iteration time in the storage current timestamp will be used.
- Second parameter is time between Job Runner iterations. Default value is 60 seconds. This time may be longer than configured because execution of tasks found during current iteration may take some time.
Discover tasks to be run
sudo -u www-data php index.php '\oat\taoScheduler\scripts\tools\SchedulerHelper' show 1518097355 1518100955
Remove expired jobs from job storage (jobs which will not be executed anymore after given date):
sudo php index.php '\oat\taoScheduler\scripts\tools\SchedulerHelper' removeExpiredJobs false 1519890884
- First parameter is dryrun mode.
false
by default. - Second parameter is time since which helper will try to find expired jobs (including given time). If parameter was not given then the last launch time of job runner will be used.
To run tasks through the task queue you may use \oat\taoTaskQueue\scripts\tools\AddTaskToQueue
action.
Note:
taoScheduler does not require taoTaskQueue extension. Make sure that task queue is installed.
use oat\taoTaskQueue\scripts\tools\AddTaskToQueue; $schedulerService->attach( '*/5 * * * *', new DateTime('now', new \DateTimeZone('utc')), AddTaskToQueue::class, [ActionClassToBeRun::class, 'param 1', 'param2'] );
Warnings
- Configure JobRunner service with common rds storage in case if scheduler is going to be run on multiserver environment.
- Please do not schedule tasks which execution of which requires a lot of resource or take long time. All the time/resources consuming tasks should create appropriate tasks in the task queue. Ideally scheduled tasks should do nothing except adding tasks to the task queue.
- Use cron syntax in case if number of occurrences is not limited.
- iCalendar syntax is more flexible but in case of large or unlimited number of repeats there may be performance issues. By default limit of repeats is 732. More information: https://github.com/simshaun/recurr