All Projects → mybuilder → Cronos Bundle

mybuilder / Cronos Bundle

Licence: mit
Easy update your crontab by using @cron annotations in Symfony commands.

Projects that are alternatives of or similar to Cronos Bundle

Featureflagsbundle
Symfony2 Bundle to implement Feature Flags to your Application
Stars: ✭ 63 (-13.7%)
Mutual labels:  bundle, symfony, symfony-bundle
Sonatacachebundle
This bundle provides caching services
Stars: ✭ 66 (-9.59%)
Mutual labels:  bundle, symfony, symfony-bundle
Symfony
The Symfony PHP framework
Stars: ✭ 26,220 (+35817.81%)
Mutual labels:  bundle, symfony, symfony-bundle
Sncredisbundle
A Redis bundle for Symfony supporting Predis and PhpRedis
Stars: ✭ 980 (+1242.47%)
Mutual labels:  bundle, symfony, symfony-bundle
Neo4j Symfony
Symfony Bundle for the Neo4j Graph Database
Stars: ✭ 69 (-5.48%)
Mutual labels:  bundle, symfony, symfony-bundle
Craueformflowbundle
Multi-step forms for your Symfony project.
Stars: ✭ 654 (+795.89%)
Mutual labels:  bundle, symfony, symfony-bundle
Beelabrecaptcha2bundle
💻 Symfony bundle for Google Recaptcha2
Stars: ✭ 47 (-35.62%)
Mutual labels:  bundle, symfony, symfony-bundle
Entityauditbundle
Audit for Doctrine Entities
Stars: ✭ 546 (+647.95%)
Mutual labels:  bundle, symfony, symfony-bundle
Foselasticabundle
Elasticsearch PHP integration for your Symfony project using Elastica.
Stars: ✭ 1,142 (+1464.38%)
Mutual labels:  bundle, symfony, symfony-bundle
Liipurlautoconverterbundle
[DEPRECATED] This bundle will add a Twig Extension for templates with a new filter for automatically converting urls and emails in a string to html links
Stars: ✭ 53 (-27.4%)
Mutual labels:  bundle, symfony, symfony-bundle
Knpgaufrettebundle
Easily use Gaufrette in your Symfony projects.
Stars: ✭ 646 (+784.93%)
Mutual labels:  bundle, symfony, symfony-bundle
Pugxgeneratorbundle
An enhancement of SensioGeneratorBundle
Stars: ✭ 58 (-20.55%)
Mutual labels:  bundle, symfony, symfony-bundle
Sensiogeneratorbundle
Generates Symfony bundles, entities, forms, CRUD, and more...
Stars: ✭ 634 (+768.49%)
Mutual labels:  bundle, symfony, symfony-bundle
Lexikpayboxbundle
LexikPayboxBundle eases the implementation of the Paybox payment system
Stars: ✭ 42 (-42.47%)
Mutual labels:  bundle, symfony, symfony-bundle
Liipfunctionaltestbundle
Some helper classes for writing functional tests in Symfony
Stars: ✭ 604 (+727.4%)
Mutual labels:  bundle, symfony, symfony-bundle
Webfactoryicutranslationbundle
Enables ICU message formatting for translations in Symfony applications.
Stars: ✭ 27 (-63.01%)
Mutual labels:  bundle, symfony, symfony-bundle
Sensiodistributionbundle
Base bundle for Symfony Distributions
Stars: ✭ 501 (+586.3%)
Mutual labels:  bundle, symfony, symfony-bundle
Sentry Symfony
The official Symfony SDK for Sentry (sentry.io)
Stars: ✭ 515 (+605.48%)
Mutual labels:  bundle, symfony, symfony-bundle
Ismaambrosigeneratorbundle
Generates Symfony2 documents, forms and CRUD for MongoDB documents
Stars: ✭ 27 (-63.01%)
Mutual labels:  bundle, symfony, symfony-bundle
Fmbbcodebundle
🔠 BBCode bundle for Symfony projects
Stars: ✭ 56 (-23.29%)
Mutual labels:  bundle, symfony, symfony-bundle

Cronos Bundle

Build Status

A bundle for Symfony 3/4/5 that allows you to use @Cron annotations to configure when cron should run your console commands.

Uses the Cronos library to do the actual output and updating.

Installation

Install with composer

Run the composer require command:

$ php composer.phar require mybuilder/cronos-bundle

Enable the bundle

Enable the bundle in the app/AppKernel.php for Symfony 3:

public function registerBundles(): array
{
    return [
        new MyBuilder\Bundle\CronosBundle\MyBuilderCronosBundle(),
    ];
}

Enable the bundle in the config/bundles.php for Symfony 4/5:

return [
    MyBuilder\Bundle\CronosBundle\MyBuilderCronosBundle::class => ['all' => true],
];

Configure the bundle

You can add the following to your config.yml (Symfony 3) / packages/my_builder_cronos.yaml (Symfony 4/5) to configure the package.

my_builder_cronos:
    exporter:
        key: unique-key
        mailto: [email protected]
        path: /bin:/usr/local/bin
        executor: php
        console: bin/console
        shell: /bin/bash
option description
key Unique key that wraps all the cron configured for the current application.
mailto Sets the default email address for all cron output to go to.
path Sets the path for all commands in the crontab it works just like the shell PATH, but it does not inherit from your environment. That means you cannot use ~ or other shell expansions.
executor Allows you to specify a program that all commands should be passed to such as /usr/local/bin/php.
console Allows you to specify the console that all commands should be passed to such as bin/console.
shell Allows you to specify which shell each program should be run with.

Usage

The first step is to add the use case for the annotation to the top of the command you want to use the @Cron annotations in.

use MyBuilder\Bundle\CronosBundle\Annotation\Cron;

Then add to the phpdoc for the command class the '@Cron' annotation which tells cron when you want it to run. This example says it should be run on the web server, every 5 minutes, and we don't want to log any output.

/**
 * Command for sending our email messages from the database.
 *
 * @Cron(minute="/5", noLogs=true, server="web")
 */
class SendQueuedEmailsCommand extends Command {}

Specifying when to run

The whole point of cron is being able to specify when a script is run therefore there are a lot of options.

You should read the general cron info for a general idea of cron and what you can use in these time fields.

Please note You CANNOT use */ in the annotations, if you want */5 just put /5 and Cronos will automatically change it to */5.

Annotation examples

annotation description
@Cron(minute="/5") Every 5 minutes
@Cron(minute="5") At the 5th minute of each hour
@Cron(minute="5", hour="8") 5 minutes past 8am every day
@Cron(minute="5", hour="8", dayOfWeek="0") 5 minutes past 8am every Sunday
@Cron(minute="5", hour="8", dayOfMonth="1") 5 minutes past 8am on first of each month
@Cron(minute="5", hour="8", dayOfMonth="1", month="1") 5 minutes past 8am on first of of January
@Cron(minute="/5", params="--user=barman") Every 5 minutes, with a custom param

Building the cron

You should run app/console cronos:dump and review what the cron file would look after it has been updated. If everything looks ok you can replace your crontab by running the command below.

app/console cronos:replace

You can also limit which commands are included in the cron file by specifying a server, and it will then only show commands which are specified for that server.

Exporting the cron

app/console cronos:dump --server=web
app/console cronos:replace --server=web

Environment

You can choose which environment you want to run the commands in cron under like this.

app/console cronos:replace --server=web --env=prod

Troubleshooting

  • When a cron line is executed it is executed with the user that owns the crontab, but it will not execute any of the users default shell files so all paths etc need to be specified in the command called from the cron line.
  • Your crontab will not be executed if you do not have usable shell in /etc/passwd
  • If your jobs don't seem to be running check the cron daemon is running, also check your username is in /etc/cron.allow and not in /etc/cron.deny.
  • Environmental substitutions do not work, you cannot use things like $PATH, $HOME, or ~/sbin.

Created by MyBuilder - Check out our blog for more insight into this and other open-source projects we release.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].