Passed
Push — master ( 510a5e...0f9b0c )
by Roman
02:40 queued 14s
created

TestController::actionPushSimpleJob()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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;
0 ignored issues
show
Bug introduced by
The trait zhuravljov\yii\queue\monitor\base\FlashTrait requires the property $session which is not provided by tests\app\controllers\TestController.
Loading history...
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