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