2017 © Pedro Peláez
 

library cron-bridge

Symfony 2 bridge which allows you to use config to configure cron to run your console commands.

image

fdevs/cron-bridge

Symfony 2 bridge which allows you to use config to configure cron to run your console commands.

  • Sunday, May 15, 2016
  • by andrey1s
  • Repository
  • 3 Watchers
  • 0 Stars
  • 207 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Cron

Easily configure cron through PHP., (*1)

Setup and Configuration

FDevsCron uses Composer, please checkout the composer website for more information., (*2)

The simple following command will install cron-bridge into your project. It also add a new entry in your composer.json and update the composer.lock as well., (*3)

$ composer require fdevs/cron-bridge

FDevsCron follows the PSR-4 convention names for its classes, which means you can easily integrate cron classes loading in your own autoloader., (*4)

Usage with Symfony framework

Enable the bundle in the kernel

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new FDevs\Bridge\Cron\FDevsCronBundle(),
        // ...
    );
}

add command

#app/config/config.yml
f_devs_cron:
    commands:
        swiftmailer:
            command: 'swiftmailer:spool:sends'
        bin:
            executor: '/usr/bin/php'
            command: 'your_best_command'

default configuration

# Default configuration for extension with alias: "f_devs_cron"
f_devs_cron:
    exporter:
        key:                  f_devs_cron # Example: generated
        mailto:               ~ # Example: cron@example.com
        path:                 '/usr/local/bin:/usr/bin:/bin' # Example: /usr/local/bin:/usr/bin:/bin
        executor:             php # Example: php
        console:              bin/console # Example: bin/console(symfony 3.0)
        shell:                ~ # Example: /bin/sh
    commands:

        # Prototype
        name:
            command:              ~ # Required, Example: swiftmailer:spool:send
            minute:               '*' # Example: */5 - Every 5 minutes
            hour:                 '*' # Example: 8 - 5 minutes past 8am every day
            day_of_week:          '*' # Example: 0 - 5 minutes past 8am every Sunday
            day:                  '*' # Example: 1 -  5 minutes past 8am on first of each month
            month:                '*' # Example: 1 - 5 minutes past 8am on first of of January
            log_file:             ~ # Example: %kernel.logs_dir%/%kernel.environment%_cron.log
            error_file:           ~ # Example: %kernel.logs_dir%/%kernel.environment%_error.log
            params:               '' # Example: --color=red

            # add if use custom executor
            executor:             ~ # Example: /usr/bin/php

use console command

$ bin/console fdevs:cron:dump
$ bin/console fdevs:cron:replace
$ bin/console fdevs:cron:delete

Usage with The Console Component

#!/usr/bin/env php
<?php
// application.php

require __DIR__.'/vendor/autoload.php';

use FDevs\Bridge\Cron\Command\DeleteCommand;
use FDevs\Bridge\Cron\Command\DumpCommand;
use FDevs\Bridge\Cron\Command\ReplaceCommand;
use FDevs\Cron\Cron;
use FDevs\Cron\CrontabUpdater;
use Symfony\Component\Console\Application;

$cron = new Cron()
// $cron configuration...

$crontabUpdater = new CrontabUpdater('uniquie_key');

$application = new Application();
$application->add(new ReplaceCommand('cron:replace', $cron, $crontabUpdater));
$application->add(new DumpCommand('cron:dump', $cron));
$application->add(new DeleteCommand('cron:delete', $crontabUpdater));
$application->run();

use in console, (*5)

$ php application.php cron:replace
$ php application.php cron:dump
$ php application.php cron:delete

Usage with The DependencyInjection Component

<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use FDevs\Bridge\Cron\DependencyInjection\FDevsCronExtension;
use FDevs\Bridge\Cron\DependencyInjection\Compiler\CronJobPass;
$container = new ContainerBuilder();
// $container configuration...

$container->registerExtension(FDevsCronExtension());
$container->addCompilerPass(new CronJobPass());

$updater = $container->get('f_devs_cron.crontab_updater');
$cron = $container->get('f_devs_cron.cron');

$updater->replace($cron);
echo strval($cron);

Created by 4devs - Check out our blog for more insight into this and other open-source projects we release., (*6)

The Versions

15/05 2016

dev-master

9999999-dev

Symfony 2 bridge which allows you to use config to configure cron to run your console commands.

  Sources   Download

MIT

The Requires

 

The Development Requires

cron crontab

15/05 2016

0.1.1

0.1.1.0

Symfony 2 bridge which allows you to use config to configure cron to run your console commands.

  Sources   Download

MIT

The Requires

 

The Development Requires

cron crontab

14/05 2016

0.1.0

0.1.0.0

Symfony 2 bridge which allows you to use config to configure cron to run your console commands.

  Sources   Download

MIT

The Requires

 

The Development Requires

cron crontab