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.
celery-php is released within celery-yii
Be sure that both Celery and celery-php are installed and working.
This means:
install Celery with
pip install Celery
install the PHP AMQP extension following these instructions. Note that celery-php contains a script to automatically do that.
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.
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!
Be the first person to leave a comment
Please login to leave your comment.