2017 © Pedro Peláez
 

symfony-bundle job-bundle

A Simple Job Bundle for Symfony 2

image

rizeway/job-bundle

A Simple Job Bundle for Symfony 2

  • Wednesday, October 24, 2012
  • by riad
  • Repository
  • 1 Watchers
  • 2 Stars
  • 163 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

RizewayJobBundle

A simple job bundle for symfony 2 projects (with doctrine), (*1)

Installation

  1. Add this bundle into your project composer.json file:, (*2)

    "require": {
      "rizeway/job-bundle": "dev-master"
    },
    
  2. Update your composer dependancies., (*3)

    composer.phar update, (*4)

  3. Register this bundle in your app/AppKernel.php, (*5)

    <?php
    
    public function registerBundles()
    {
        $bundles = array(
            // ...some other bundles...
            new Rizeway\JobBundle\RizewayJobBundle(),
        );
    
  4. Update your database schema, (*6)

    php app/console doctrine:database:update --force, (*7)

Usage

  1. Add the daemon to your cron tab, (*8)

    php app/console rizeway:job:daemon, (*9)

  2. Creating a Job, (*10)

A job is a class that implements Rizeway/JobBundle/JobHandler/JobHandlerInterface (you can also extends Rizeway/JobBundle/JobHandler/ContainerAwareJobHandler), (*11)

Example:, (*12)

<?php

namespace MyBundle\JobHandler;

use Rizeway\JobBundle\JobHandler\ContainerAwareJobHandler;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class MyJobHandler extends ContainerAwareJobHandler
{
    protected function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setRequired(array(
            'my_required_option',
        ));
    }

    public function run()
    {
        $this->log('My Option Is : '.$this->getOption('my_required_option'));
        ....
    }
  1. Scheduling a job

Scheduling a job is done like this, (*13)

<?php

namespace MyBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Rizeway\JobBundle\Entity\Job;

class myController extends Controller
{
    public function myAction()
    {
        $job = new Job();
        $job->setName('Job Name');
        $job->setType('Job Type');
        $job->setClassname('\MyBundle\JobHandler\MyJobHandler');
        $job->setOptions(array(
            'my_required_option'   => 'option_value'
        ));

        $this->getDoctrine()->getEntityManager()->persist($job);
        $this->getDoctrine()->getEntityManager()->flush();
        ....
    }

Advanced Usage

  1. Logger

The DoctrineLogger instance is available through a service. If you want to create your own Logger class and use it in the DaemonCommand, just create a new class which implements the JobLoggerInterface and declare it as a service., (*14)

Below is an example:, (*15)

parameters:
    rizeway_job.logger.class: Acme\AcmeBundle\Logger\AcmeLogger

The Versions

24/10 2012

dev-master

9999999-dev http://rizeway.com

A Simple Job Bundle for Symfony 2

  Sources   Download

MIT

The Requires

  • php >=5.3.3