-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGearmanController.php
56 lines (45 loc) · 1.14 KB
/
GearmanController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace ferrumfist\yii\gearman;
use Yii;
use yii\helpers\Console;
use ferrumfist\yii\gearman\Process;
use ferrumfist\yii\gearman\MasterApplication;
class GearmanController extends \CController
{
/**
* @var boolean whether to run the forked process.
*/
protected $fork = true;
public $gearmanComponent = 'gearman';
protected function getMaster(){
return new MasterApplication($this->gearmanComponent, $this->fork);
}
public function actionStart()
{
$master = $this->getMaster();
$master->start();
}
public function actionStop()
{
$master = $this->getMaster();
$master->stop();
}
public function actionRestart()
{
$master = $this->getMaster();
$master->restart();
}
public function options($id)
{
$options = [];
if (in_array($id, ['start', 'restart'])) {
$options = ['fork'];
}
return array_merge(parent::options($id), $options);
}
protected function getApplication()
{
$component = Yii::$app->get($this->gearmanComponent);
return $component->getApplication();
}
}