1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace tests\app\controllers; |
4
|
|
|
|
5
|
|
|
use tests\app\jobs\NotVoidJob; |
6
|
|
|
use tests\app\jobs\RecursionJob; |
7
|
|
|
use tests\app\jobs\SimpleJob; |
8
|
|
|
use Yii; |
9
|
|
|
use yii\web\Controller; |
10
|
|
|
use zhuravljov\yii\queue\monitor\base\FlashTrait; |
11
|
|
|
|
12
|
|
|
class TestController extends Controller |
13
|
|
|
{ |
14
|
|
|
use FlashTrait; |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Home page with redirecting to a base page of the module. |
18
|
|
|
*/ |
19
|
|
|
public function actionIndex() |
20
|
|
|
{ |
21
|
|
|
return $this->redirect(['/qmonitor']); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function actionPushSimpleJob() |
25
|
|
|
{ |
26
|
|
|
$this->getQueue()->push(new SimpleJob()); |
27
|
|
|
return $this->success('A simple job has been pushed.')->goBackward(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function actionPushRecursionJob() |
31
|
|
|
{ |
32
|
|
|
$this->getQueue()->push(new RecursionJob()); |
33
|
|
|
return $this->success('A recursion job has been pushed.')->goBackward(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function actionPushManyRecursionJobs($count = 10) |
37
|
|
|
{ |
38
|
|
|
for ($i = 0; $i < $count; $i++) { |
39
|
|
|
$this->getQueue()->push(new RecursionJob()); |
40
|
|
|
} |
41
|
|
|
return $this->success("$count recursion jobs have been pushed.")->goBackward(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function actionPushNotVoidJob() |
45
|
|
|
{ |
46
|
|
|
$this->getQueue()->push(new NotVoidJob()); |
47
|
|
|
return $this->success('Not void job has been pushed.')->goBackward(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return \yii\queue\Queue |
52
|
|
|
*/ |
53
|
|
|
protected function getQueue() |
54
|
|
|
{ |
55
|
|
|
return Yii::$app->queue; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return \yii\web\Response |
60
|
|
|
*/ |
61
|
|
|
protected function goBackward() |
62
|
|
|
{ |
63
|
|
|
return $this->redirect(Yii::$app->request->getReferrer() ?: Yii::$app->getHomeUrl()); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|