-
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
537 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Stomp драйвер | ||
================ | ||
|
||
Драйвер работает с очередью на базе ActiveMQ. | ||
|
||
В приложении должно быть установлено расширение `enqueue/stomp`. | ||
|
||
Пример настройки: | ||
|
||
```php | ||
return [ | ||
'bootstrap' => [ | ||
'queue', // Компонент регистрирует свои консольные команды | ||
], | ||
'components' => [ | ||
'queue' => [ | ||
'class' => \yii\queue\stomp\Queue::class, | ||
'host' => 'localhost', | ||
'port' => 61613, | ||
'queueName' => 'queue', | ||
], | ||
], | ||
]; | ||
``` | ||
|
||
Консоль | ||
------- | ||
|
||
Для обработки очереди используются консольные команды. | ||
|
||
```sh | ||
yii queue/listen | ||
``` | ||
|
||
Команда `listen` запускает обработку очереди в режиме демона. Очередь опрашивается непрерывно. | ||
Если добавляются новые задания, то они сразу же извлекаются и выполняются. Способ наиболее эфективен | ||
если запускать команду через [supervisor](worker.md#supervisor) или [systemd](worker.md#systemd). | ||
|
||
Для команды `listen` доступны следующие опции: | ||
|
||
- `--verbose`, `-v`: состояние обработки заданий выводится в консоль. | ||
- `--isolate`: каждое задание выполняется в отдельном дочернем процессе. | ||
- `--color`: подсветка вывода в режиме `--verbose`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Stomp Driver | ||
=============== | ||
|
||
|
||
This driver works with ActiveMQ queues. | ||
|
||
It requires the `enqueue/stomp` package. | ||
|
||
Configuration example: | ||
|
||
```php | ||
return [ | ||
'bootstrap' => [ | ||
'queue', // The component registers its own console commands | ||
], | ||
'components' => [ | ||
'queue' => [ | ||
'class' => \yii\queue\stomp\Queue::class, | ||
'host' => 'localhost', | ||
'port' => 61613, | ||
'queueName' => 'queue', | ||
], | ||
], | ||
]; | ||
``` | ||
|
||
Console | ||
------- | ||
|
||
A console command is used to execute queued jobs. | ||
|
||
```sh | ||
yii queue/listen [timeout] | ||
``` | ||
|
||
The `listen` command launches a daemon which infinitely queries the queue. If there are new tasks | ||
they're immediately obtained and executed. The `timeout` parameter specifies the number of seconds to sleep between | ||
querying the queue. This method is most efficient when the command is properly daemonized via | ||
[supervisor](worker.md#supervisor) or [systemd](worker.md#systemd). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* @link http://www.yiiframework.com/ | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @license http://www.yiiframework.com/license/ | ||
*/ | ||
|
||
namespace yii\queue\stomp; | ||
|
||
use yii\console\Exception; | ||
use yii\queue\cli\Command as CliCommand; | ||
|
||
/** | ||
* Manages application stomp-queue. | ||
* | ||
* @author Sergey Vershinin <[email protected]> | ||
* @since 2.3.0 | ||
*/ | ||
class Command extends CliCommand | ||
{ | ||
/** | ||
* @var Queue | ||
*/ | ||
public $queue; | ||
|
||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function isWorkerAction($actionID) | ||
{ | ||
return in_array($actionID, ['run', 'listen']); | ||
} | ||
|
||
|
||
/** | ||
* Runs all jobs from stomp-queue. | ||
* It can be used as cron job. | ||
* | ||
* @return null|int exit code. | ||
*/ | ||
public function actionRun() | ||
{ | ||
return $this->queue->run(false); | ||
} | ||
|
||
/** | ||
* Listens stomp-queue and runs new jobs. | ||
* It can be used as daemon process. | ||
* | ||
* @param int $timeout number of seconds to wait a job. | ||
* @throws Exception when params are invalid. | ||
* @return null|int exit code. | ||
*/ | ||
public function actionListen($timeout = 3) | ||
{ | ||
if (!is_numeric($timeout)) { | ||
throw new Exception('Timeout must be numeric.'); | ||
} | ||
if ($timeout < 1) { | ||
throw new Exception('Timeout must be greater that zero.'); | ||
} | ||
|
||
return $this->queue->run(true, $timeout); | ||
} | ||
} |
Oops, something went wrong.