celery-yii celery-yii is a YII extension to dispatch Celery (http://celeryproject.org) tasks

  1. Requirements
  2. Usage
  3. Resources

celery-yii is a Yii extension to dispatch Celery tasks.

It is a wrapper to celery-php, released under the same BSD license.

This extension is unrelated with the Yii AMQP extension. In case you don't actually need Celery, but just communicating via AMQP you may want to check that.

Requirements

celery-php is released within celery-yii

Be sure that both Celery and celery-php are installed and working.

This means:

  1. install Celery with ~~~ pip install Celery ~~~

  2. install the PHP AMQP extension following these instructions. Note that celery-php contains a script to automatically do that.

  3. configure Celery as celery-php requires, i.e. adding the following configuration: ~~~ CELERY_RESULT_SERIALIZER = "json" CELERY_TASK_RESULT_EXPIRES = None ~~~ Note: at the time of writing (2012-06-16) the documentation of celery-php reports a bad configuration parameter.

Usage

Download the package and decompress it in the protected/extensions directory.

Add the following configuration to protected/config/main.php:

'components'=>array(
    ...
    'celery' => array(
        'class' => 'ext.celery-yii.ECelery',

        // login, password and virtual host
        'login' => 'myuser',
        'password' => 'mypass',
        'vhost' => 'myvhost',

        // probably, you don't need to change host & port
        //'host' => 'localhost',
        //'port' => 5672,

        // almost surely, you don't need to change exchange & binding
        //'exchange' => 'celery',
        //'binding' => 'celery',
    ),
    ...

Send tasks to Celery:

$result = Yii::app()->celery->postTask('tasks.add', array(2,2));

You can either ignore $result if you just want to send async tasks to the backend, or use $result exactly as explained in celery-php, for instance:

$result->get();
if($result->successful())
{
    echo $result->result;
}

Enjoy!

Resources

1 0
8 followers
444 downloads
Yii Version: 1.1
License: (not set)
Category: Web Service
Developed by: ema
Created on: Jun 17, 2012
Last updated: 11 years ago

Downloads

show all

Related Extensions