Skip to content

Commit f30ae88

Browse files
committed
experimental redis pubsub support
1 parent c946753 commit f30ae88

11 files changed

+909
-207
lines changed

AsyncComponent.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public function receiveTask($queueName)
4747
return $this->transport->receive($queueName);
4848
}
4949

50+
public function waitAndReceive($queueName) {
51+
return $this->transport->waitAndReceive($queueName);
52+
}
53+
5054
/**
5155
* @param AsyncTask $task
5256
* @return bool

commands/AsyncWorkerCommand.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use bazilio\async\models\AsyncTask;
4+
5+
class AsyncWorkerCommand extends \yii\console\Controller
6+
{
7+
/**
8+
* @param string|null $queueName
9+
*/
10+
public function actionExecute($queueName = null)
11+
{
12+
/** @var AsyncTask $task */
13+
while ($task = \Yii::$app->async->receiveTask($queueName ?: AsyncTask::$queueName)) {
14+
$task->execute();
15+
\Yii::$app->async->acknowledgeTask($task);
16+
}
17+
}
18+
19+
/**
20+
* @param string|null $queueName
21+
*/
22+
public function actionDaemon($queueName = null)
23+
{
24+
/** @var AsyncTask $task */
25+
while ($task = \Yii::$app->asyncAmqp->waitAndReceive($queueName ?: AsyncTask::$queueName)) {
26+
$task->execute();
27+
\Yii::$app->asyncAmqp->acknowledgeTask($task);
28+
}
29+
}
30+
}

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
"yiisoft/yii2": "*"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "3.7.*",
19+
"phpunit/phpunit": "4.6.*",
2020
"yiisoft/yii2-codeception": "*",
21-
"codeception/codeception": "*",
21+
"codeception/codeception": "2.0.*",
2222
"pdezwart/php-amqp": "dev-master",
23-
"yiisoft/yii2-redis": "*"
23+
"yiisoft/yii2-redis": "*",
24+
"kriswallsmith/spork": "*"
2425
},
2526
"autoload": {
2627
"psr-4": {

0 commit comments

Comments
 (0)