skrip42 / cron-bundle
Symfony Cron-bundle
Installs: 262
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.1.3
- skrip42/advanced-repository: ^2.2
- symfony/config: ^4.0|^5.0
- symfony/dependency-injection: ^4.0|^5.0
Requires (Dev)
- doctrine/doctrine-bundle: ^1.5|^2.0
- symfony/console: ^4.4|^5.0
- symfony/yaml: ^4.4|^5.0
This package is auto-updated.
Last update: 2024-10-28 13:44:34 UTC
README
task scheduler for symfony witch extended syntax similar to cron.
install:
- run
composer require skrip42/cron-bundle
- create database
php ./bin/console make:migration
andphp ./bin/console doctrine:migration:migrate
- add
* * * * * ./bin/console cron:run
in you crontab
schedule-task syntax:
task pattern is {minute}_{house}_{day}_{weekday}_{month}_{year}
Operators can be combined, for example: 0_0_*/2-1_*_*_*
- will be executed at midnight on odd days.
available command:
cron:add
- interactiv adding cron taskcron:closest
- show list of closest taskcron:list
- show list of cron taskcron:list --all
- show list of all activity status cron taskcron:optimize
- disable outdated cron taskscron:run
- run actual taskcron:update $id
- update cron taskcron:toggle $id
- toggle cron task activity
usage:
....... //you namespace declaration use Skrip42\Bundle\CronBundle\Services\Cron; use Skrip42\Bundle\CronBundle\Component\Pattern; ....... //you class declaration protected $cron; //instance of Cron service public function __construct(Cron $cron) { $this->cron = $cron } ........ //in you method $this->cron->getActualOnCurrentTime(); // return array of actual Schedule entity $this->cron->optimize(); // disable outdated cron tasks $this->cron->closestList($count); // return $count closest task in format: [$id, $command, $c] $this->cron->getList($all); // return all schedule task? if $all = true includes disabled task $this->cron->addSchedule($patternString, $commandString); // create new schedule task $this->cron->toggleSchedule($id); // toggle schedule task activity $this->cron->updateSchedule($id, $patternString, $commandString); // update schedule task $pattern = new Pattern($patternString); // get pattern object $pattern->test(new DateTime('NOW')); // test pattern for match date $pattern->getClosest($count); //return $count closest date that match pattern $schedule = reset($this->cron->getList()); // schedule is standart doctrine entity $schedule->getId(); //return id $schedule->getCommand(); // return command string $schedule->setCommand($commandString); // set command string to schedule $schedule->getPattern(); // return pattern string $schedule->setPattern($patternString); // set pattern string to schedule $schedule->toggleActive(); // toggle schedule activity $this->container->get('doctrine')->getManager()->flush(); // to save change ........