Skip to content

Comparon/megacron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Comparon Megacron Bundle

This bundle is designed around the idea to schedule the commands within the project and therefore under VCS control.

IMPORTANT

Use this version with at least symfony 4

Installation

  1. Add the bundle to your project as a composer dependency:
// composer.json
{
    // ...
    require: {
        // ...
        "comparon/megacron": "dev-master"
    },
    // ...
    "repositories": [
        // ...
        {
            "type": "vcs",
            "url": "https://github.com/Comparon/Megacron.git"
        }
    ]
}
  1. Update your composer installation:
composer update
  1. Add the bundle to bundles.php:
// config/bundles.php
return  [
        // ...
        Comparon\MegacronBundle\ComparonMegacronBundle::class => [ 'all' => true],
    ];
  1. Add command to services.yaml
    Comparon\MegacronBundle\Command\SchedulerCommand:
        arguments:
          $projectDir: '%kernel.project_dir%'
        tags:
          - 'console.command'

Start using the bundle

Schedule your Command

All you have to do is to implement the TaskInterface (and therefore the method getTaskConfigurations()) in your Command:

class DemoCommand extends ContainerAwareCommand implements TaskInterface
{
    protected function configure()
    {
        // ...
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // ...
    }

    /**
     * @return TaskConfiguration[]
     */
    public function getTaskConfigurations()
    {
        $configs = [];

        $configMonday = new TaskConfiguration();
        $configMonday->setCronExpression('* * * * 1');
        $configs[] = $configMonday;

        $configTuesday = new TaskConfiguration();
        $configTuesday
            ->setCronExpression('0 * * * 2')
            ->setWithOverlapping(false)
        ;
        $configs[] = $configTuesday;

        return $configs;
    }
}

Running your cron jobs automatically

To facilitate this, you can create a cron job on your system like this:

* * * * * <path to console> comparon:scheduler:run