bsJobQueuePlugin - 0.0.2

bsJobQueue

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

bsJobQueue plugin

Overview

This plugin allow to postpone the execution of function from any Table class.

Installation

1.Copy the source in the plugins folder

cd plugins
svn co http://svn.symfony-project.com/plugins/bsJobQueuePlugin

2.Generate the models. It will create the model bsJobQueue.

./symfony doctrine:build-model
./symfony cc

3.Create the table job_queue:

CREATE TABLE `job_queue` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`job_params` text,
`table_class_name` varchar(255) DEFAULT NULL,
`function_name` varchar(255) DEFAULT NULL,
`status` varchar(255) DEFAULT NULL,
`note` text,
`duration` float DEFAULT NULL,
`executed_at` datetime DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
)

Configuration

1.Enable the plugin into your ProjectConfiguration

Edit config/ProjectConfiguration.class.php to enable the bsBysoftPlugin plugin, and add the line below in the setup function

$this->enablePlugins('bsBysoftPlugin');

2.Add a cron in the system to call the following task every 5 min:

./symfony jobQueue:process

How to create a job

//Create a job for sending the email
$params = array(
    'user_id' => $id,
);
Doctrine_Core::getTable("bsJobQueue")->createNewJob('User', 'sendEmailPassword', $params);

This will create a new record in the table job_queue.

The previous code supposed that you have a method sendEmailPassword in UserTable class:

class UserTable extends Doctrine_Table {

    public function sendEmailPassword($userId) {
        // code to send the email
    }
}

How to execute a job

./symfony jobQueue:process

Display statistics about the jobQeue

./symfony jobQueue:stat
>> done                 10981
>> has_error            394

It will run all the jobQueue recorded in job_queue table.

TODO

  • Allow recurrent task