Git Product home page Git Product logo

cronjob-commands-bundle's Introduction

Symfony commands as cron jobs

Using this bundle you can manage cron jobs with yaml configuration of your Symfony application.

It:

  • provides a simple way of running commands according to cron expressions
  • supports command arguments, options and verbosity settings
  • prints full output of running commands
  • uses https://github.com/dragonmantank/cron-expression to resolve cron expressions

Installing

Update composer.json:

composer require mkijak/cronjob-commands-bundle

Enable the bundle in Symfony application:

# config/bundles.php 

Mkijak\CronJobCommandsBundle\CronJobCommandsBundle::class => ['all' => true],

Configuration

It is recommended to set the timezone (default timezone is UTC and server settings aren't considered).

# config/packages/cron_job_commands.yaml
cron_job_commands:
    timezone: UTC
    schedule:
        command1:
            name: app:command #command name registered in symfony
            enabled: true #default: true
            cron_expression: "* * * * *" #supports also predefined keywords e. g. "@daily", see https://github.com/dragonmantank/cron-expression
            arguments:
                argument1name: value
                argument2name: value
            options:
                option1name: value
                option2name: value
            multivalue_options:
                option1name:
                    - value1
                    - value2
                option2name:
                    - value1
        command2:
            name: app:another_command
            cron_expression: "@daily"

Usage

Run the "trigger-command" once per minute. Consider using quiet mode for less output.

For cron: add to crontab (crontab -e):

* * * * * /path/to/symfony/bin/console cron_commands:trigger -q

In the quiet mode you can still display some messages from your commands setting visibility level as a second parameter of the writeln function (or 3rd parameter of the write function):

use Symfony\Component\Console\Output\OutputInterface;

/** @var OutputInterface $output */
$output->writeln('<error>Message</error>', OutputInterface::VERBOSITY_QUIET)

Requirements

  • PHP 7.1 or above
  • Symfony 4.0 or newer

Licence

Symfony commands as cron jobs is licenced under the MIT Licence.

cronjob-commands-bundle's People

Contributors

mkijak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.