Developed with love by KnpLabs Hire us for your project!
44

TaskSchedulerBundle

by rewieer

Task Scheduler with CRON for Symfony

Task Scheduler Bundle

A task scheduler for Symfony applications using CRON jobs porting that allows you to run tasks periodically.

Requirements

For this bundle to work, you must be able to define CRON jobs on your server.

Installation

Start by adding the bundle to your composer.json : composer require rewieer/taskschedulerbundle

Symfony Flex will automatically enable that bundle for you. If you are not using Flex yet, add the bundle to your AppKernel.php :
php
// in AppKernel::registerBundles()
$bundles = array(
// ...
new Rewieer\TaskSchedulerBundle\RewieerTaskSchedulerBundle(),
// ...
);

You're ready to start scheduling!

Usage

First, add the following line to your CRON tabs : * * * * * php /path/to/your/project/bin/console ts:run >> /dev/null 2>&1

This will call the scheduler, which will review all scheduled tasks and dispatch accordingly. You can call a task directly by providing it's ID as a parameter to the command. Note that this ID is generated by the scheduler and is in no way related to the service itself.

The >> /dev/null 2>&1 option discards the printed results of the tasks. Removing it allows to send it by email instead. This may vary so please refer to your server's configuration.

You then need to create a task. Tasks can be any service! You just have to give it the ts.task tag and implement TaskInterface, or for simplicity extend from AbstractScheduledTask.

In Foo\Bar\Task
```php
use Rewieer\TaskSchedulerBundle\Task\AbstractScheduledTask;
use Rewieer\TaskSchedulerBundle\Task\Schedule;

class Task extends AbstractScheduledTask {
protected function initialize(Schedule $schedule) {
$schedule
->everyMinutes(5); // Perform the task every 5 minutes
}

public function run() {
// Do suff
}
}
```

Your task is now scheduled and will be called every 5 minutes.

You're good to go! You can now check your logs to see if this is working.

Copyright (c) 2018 Anthony Cyrille

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
rewieer_task_scheduler:  []
  • Merge pull request #18 from NicoHaase/fix/symfony-flex
    By web-flow, 4 months ago
  • Properly adding tags through the extension (rather than having a service configuration for this)
    By NicoHaase, 4 months ago
  • Merge pull request #16 from NicoHaase/symfony-flex
    By web-flow, 4 months ago
  • Changing the package type to "symfony-bundle" to enable Symfony Flex
    By NicoHaase, 4 months ago
  • Merge pull request #15 from NicoHaase/symfony5-compatibility
    By web-flow, 6 months ago
  • Symfony 5 compatibility
    By NicoHaase, 6 months ago
  • Merge pull request #13 from paha77/cron-setpart-parameter-type
    By web-flow, 1 year ago
  • Converting parameter from integer to string which fits to cron function
    By , 1 year ago
  • Merge pull request #10 from NicoHaase/symfony43-compatibility
    By web-flow, 1 year ago
  • Adding the proper dependencies, as the commands did not know about the container anymore
    By , 1 year ago
  • Merge pull request #9 from NicoHaase/symfony43-compatibility
    By web-flow, 1 year ago
  • Refreshed dependencies
    By NicoHaase, 1 year ago
  • Making the Bundle configuration compatible with Sf >= 4.2
    By NicoHaase, 1 year ago
  • Making both commands compatible with Sf >= 4.2 by removing the deprecated ContainerAwareCommand
    By NicoHaase, 1 year ago
  • Including Travis CI to run tests after checkin, removing Sf 2.x from allowed dependencies
    By NicoHaase, 1 year ago
  • Merge pull request #5 from Zasco/add_php7_req
    By web-flow, 1 year ago
  • Merge pull request #3 from Zasco/master
    By web-flow, 1 year ago
  • [Fix] Add PHP7 requirement
    By web-flow, 1 year ago
  • [Doc] Update README.md
    By web-flow, 1 year ago
  • registered commands
    By rewieer, 2 years ago
  • added running single task + listing with ID
    By rewieer, 2 years ago
  • removed version
    By rewieer, 2 years ago
  • added version
    By rewieer, 2 years ago
  • made it usable for S4
    By rewieer, 2 years ago
  • fixed details
    By rewieer, 2 years ago
  • fixed details
    By rewieer, 2 years ago
  • added README content
    By rewieer, 2 years ago
  • initial commit
    By rewieer, 2 years ago