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

cron-bundle

by shapecode

This bundle provides a simple interface for registering repeated scheduled tasks within your application.

Shapecode - Cron Bundle

paypal

PHP Version
Latest Stable Version
Latest Unstable Version
Total Downloads
Monthly Downloads
Daily Downloads
License

This bundle provides a simple interface for registering repeated scheduled
tasks within your application.

Install instructions

Installing this bundle can be done through these simple steps:

Add the bundle to your project through composer:
bash
composer require shapecode/cron-bundle

Add the bundle to your application kernel:
```php
<?php

// application/ApplicationKernel.php
public function registerBundles()
{
// ...
$bundles = array(
// ...
new Shapecode\Bundle\CronBundle\ShapecodeCronBundle(),
);
// ...

return $bundles;

}
```

Update your DB schema ...

... with Doctrine standard method ...
bash
php bin/console doctrine:schema:update --force

Creating your own tasks

Creating your own tasks with CronBundle couldn't be easier - all you have to do is create a normal Symfony2 Command (or ContainerAwareCommand) and tag it with the CronJob annotation, as demonstrated below:

<?php

namespace App\DemoBundle\Command;

use Shapecode\Bundle\CronBundle\Annotation\CronJob;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Class DemoCommand
 * @package App\DemoBundle\Command
 * @author Nikita Loges
 *
 * @CronJob("*\/5 * * * *")
 * Will be executed every 5 minutes
 */
class DemoCommand extends Command
{

    /**
     * @inheritdoc
     */
    public function configure()
    {
        // Must have a name configured
        // ...
    }

    /**
     * @inheritdoc
     */
    public function execute(InputInterface $input, OutputInterface $output)
    {
        // Your code here
    }
}

The interval spec ("*\/5 * * * *" in the above example) use the standard cronjob schedule format and can be modified whenever you choose. You have to escape the / in this example because it would close the annotation.
You can also register your command multiple times by using the annotation more than once with different values.
For your CronJob to be scanned and included in future runs, you must first run php bin/console shapecode:cron:scan - it will be scheduled to run the next time you run php app/console shapecode:cron:run

Register your new Crons:
bash
$ php bin/console shapecode:cron:scan
$ php bin/console shapecode:cron:run

Running your cron jobs automatically

This bundle is designed around the idea that your tasks will be run with a minimum interval - the tasks will be run no more frequently than you schedule them, but they can only run when you trigger then (by running bin/console shapecode:cron:run).

To facilitate this, you can create a cron job on your system like this:
bash
*/5 * * * * php /path/to/symfony/bin/console shapecode:cron:run

This will schedule your tasks to run at most every 5 minutes - for instance, tasks which are scheduled to run every 3 minutes will only run every 5 minutes.

The MIT License (MIT)

Copyright (c) 2015-2019 Shapecode, Nikita Loges

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.
  • remove @company
    By nicklog, 1 year ago
  • dev
    By nicklog, 1 year ago
  • badges
    By nicklog, 1 year ago
  • remove deprecated class example
    By nicklog, 1 year ago
  • remove donate btn
    By nicklog, 1 year ago
  • Merge branch 'release/3.0'
    By nicklog, 1 year ago
  • fix
    By nicklog, 1 year ago
  • dev release
    By nicklog, 1 year ago
  • Merge branch 'release/3.0' into release/3.3
    By nicklog, 1 year ago
  • add to string function
    By nicklog, 1 year ago
  • remove sonata admin
    By nicklog, 1 year ago
  • types
    By nicklog, 1 year ago
  • license
    By nicklog, 1 year ago
  • auto conf and wire
    By nicklog, 1 year ago
  • remove dev stuff
    By nicklog, 1 year ago
  • increase php requiurement
    By nicklog, 1 year ago
  • Merge pull request #17 from garvek/issue/15
    By web-flow, 1 year ago
  • type
    By nicklog, 1 year ago
  • Merge branch 'release/3.3'
    By nicklog, 1 year ago
  • Rework "Fix root node deprecation as reported in https://github.com/shapecode/cron-bundle/issues/15"
    By Sylvain THESNIERES, 1 year ago
  • add max instances
    By nicklog, 1 year ago
  • Merge branch 'release/3.3'
    By , 1 year ago
  • merge
    By nicklog, 1 year ago
  • Update README.md
    By web-flow, 1 year ago
  • correct description
    By nicklog, 1 year ago
  • 3.3 dev release
    By nicklog, 1 year ago
  • remove shortcut
    By nicklog, 1 year ago
  • Update README.md
    By web-flow, 1 year ago
  • Merge remote-tracking branch 'lsimeonov/master'
    By nicklog, 2 years ago
  • Merge branch 'release/3.2'
    By nicklog, 2 years ago