GithubHelp home page GithubHelp logo

cronbundle's Introduction

ColourStream Cron Bundle

This bundle provides a simple interface for registering repeated scheduled tasks within your application, including support for installs where the host does not allow for command-line access (TODO).

This bundle is tested only against Symfony 2.1. It will likely work with Symfony 2.0, but YMMV

Installation

Installing this bundle can be done through these simple steps:

  1. Add the bundle to your project as a composer dependency:
// composer.json
{
    // ...
    require: {
        // ...
        "colourstream/cron-bundle": "dev-master"
    }
}
  1. Update your composer installation:
composer update
  1. Add the bundle to your application kernel:
// application/ApplicationKernel.php
public function registerBundles()
{
	// ...
	$bundle = array(
		// ...
        new ColourStream\Bundle\CronBundle\ColourStreamCronBundle(),
	);
    // ...

    return $bundles;
}
  1. Update your DB schema
app/console doctrine:schema:update
  1. Start using the bundle:
app/console cron:scan
app/console 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 app/console cron:run, or the forthcoming web endpoint, for use with webcron services).

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

*/5 * * * * /path/to/symfony/install/app/console 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.

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:

/**
 * @CronJob("PT1H")
 */
class DemoCommand extends Command
{
    public function configure()
    {
		// Must have a name configured
		// ...
    }
    
    public function execute(InputInterface $input, OutputInterface $output)
    {
		// Your code here
    }
}

The interval spec ("PT1H" in the above example) is documented on the DateInterval documentation page, and can be modified whenever you choose. For your CronJob to be scanned and included in future runs, you must first run app/console cron:scan - it will be scheduled to run the next time you run app/console cron:run

cronbundle's People

Contributors

predakanga avatar yberkholz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cronbundle's Issues

Removing a command throws exception

When a command is removed, cron:scan throws an exception when trying to remove the command from the database. It seems related to the foreign key constraints:

Deleting job: xx

  [Doctrine\DBAL\DBALException]                                                                                                                                                                                                                    
  An exception occurred while executing 'DELETE FROM CronJob WHERE id = ?' with params {"1":1}:                                                                                                                                                    

  SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`xx`.`cronjobresult`, CONSTRAINT `FK_301AF175BE04EA9` FOREIGN KEY (`job_id`) REFERENCES `CronJob` (`id`))  


  [PDOException]                                                                                                                                                                                                                                   
  SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`xx`.`cronjobresult`, CONSTRAINT `FK_301AF175BE04EA9` FOREIGN KEY (`job_id`) REFERENCES `CronJob` (`id`))  

When running cron:run manually result is not set

[Doctrine\DBAL\DBALException]
An exception occurred while executing 'INSERT INTO CronJobResult (runAt, runTime, result, output, job_id) VALUES (?, ?, ?, ?, ?)' with params {"1":"201
3-04-10 17:22:42","2":0.055889844894409,"3":null,"4":"Done and updated 11 profiles.\n","5":1}:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'result' cannot be null

Shall we allow null for this column?

Changing interval throws exception

When changing the interval of a Command, an exception is thrown:

  [BadMethodCallException]                                                                        
  Unknown property 'interval' on annotation 'ColourStream\Bundle\CronBundle\Annotation\CronJob'.  

How to reproduce:

  1. Create command with (at)CronJob annotation
  2. run cron:scan
  3. Change interval
  4. run cron:scan

Stable release

Please make this bundle available with composer with "minimum-stability" : "stable".
I think that the right way to do this is to add a tag (release)

Feature request: Specify time of day for a job

Hello, and thanks for a great bundle.

I'd like to discuss a new feature which I would like to see in this bundle. In a project of mine I'd like to send out reminders every day at a specific time. I tried setting the nextRun date to the time I want but it seems like the value is being incremented with every run.

Would a annotated option that specifies which time of day a job should be run make sense? In a unix crontab this is possible using the crontab file syntax. Maybe something simplified could be used for this bundle?

I'd be willing to dig into the code and maybe submit a PR, but would like to get your input first.

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.