Completed
Push — master ( c1d220...5e1e72 )
by Phil
07:50 queued 04:46
created

DefaultController::removeQueueAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
3
namespace ResqueBundle\Resque\Controller;
4
5
use ResqueBundle\Resque\Resque;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpFoundation\Response;
9
10
/**
11
 * Class DefaultController
12
 * @package ResqueBundle\Resque\Controller
13
 */
14
class DefaultController extends Controller
15
{
16
    /**
17
     * @return Response
18
     */
19
    public function indexAction()
20
    {
21
        $this->getResque()->pruneDeadWorkers();
22
23
        return $this->render(
24
            'ResqueBundle:Default:index.html.twig',
25
            [
26
                'resque' => $this->getResque(),
27
            ]
28
        );
29
    }
30
31
    /**
32
     * @return Resque
33
     */
34
    protected function getResque()
35
    {
36
        return $this->get('resque');
37
    }
38
39
    /**
40
     * @param $queue
41
     * @param Request $request
42
     * @return Response
43
     */
44
    public function showQueueAction($queue, Request $request)
45
    {
46
        list($start, $count, $showingAll) = $this->getShowParameters($request);
47
48
        $queue = $this->getResque()->getQueue($queue);
49
        $jobs = $queue->getJobs($start, $count);
50
51
        if (!$showingAll) {
52
            $jobs = array_reverse($jobs);
53
        }
54
55
        return $this->render(
56
            'ResqueBundle:Default:queue_show.html.twig',
57
            [
58
                'queue'      => $queue,
59
                'jobs'       => $jobs,
60
                'showingAll' => $showingAll
61
            ]
62
        );
63
    }
64
65
    public function removeQueueAction($queue, Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
    {
67
        $queue = $this->getResque()->getQueue($queue);
68
        $count = $queue->clear();
69
        $queue->remove();
70
71
        $this->addFlash('info', 'Remove ' . $queue->getName() . ' queue and ' . $count . ' jobs.');
72
73
        return $this->redirectToRoute('ResqueBundle_homepage');
74
    }
75
76
77
    /**
78
     * Decide which parts of a job queue to show
79
     *
80
     * @param Request $request
81
     *
82
     * @return array
83
     */
84
    private function getShowParameters(Request $request)
85
    {
86
        $showingAll = FALSE;
87
        $start = -100;
88
        $count = -1;
89
90
        if ($request->query->has('all')) {
91
            $start = 0;
92
            $count = -1;
93
            $showingAll = TRUE;
94
        }
95
96
        return [$start, $count, $showingAll];
97
    }
98
99
    /**
100
     * @param Request $request
101
     * @return Response
102
     */
103
    public function listFailedAction(Request $request)
104
    {
105
        list($start, $count, $showingAll) = $this->getShowParameters($request);
106
107
        $jobs = $this->getResque()->getFailedJobs($start, $count);
108
109
        if (!$showingAll) {
110
            $jobs = array_reverse($jobs);
111
        }
112
113
        return $this->render(
114
            'ResqueBundle:Default:failed_list.html.twig',
115
            [
116
                'jobs'       => $jobs,
117
                'showingAll' => $showingAll,
118
            ]
119
        );
120
    }
121
122
    /**
123
     * @return Response
124
     */
125
    public function workersAction()
126
    {
127
        return $this->render(
128
            'ResqueBundle:Default:workers.html.twig',
129
            [
130
                'resque' => $this->getResque(),
131
            ]
132
        );
133
    }
134
135
    /**
136
     * @return Response
137
     */
138
    public function listScheduledAction()
139
    {
140
        return $this->render(
141
            'ResqueBundle:Default:scheduled_list.html.twig',
142
            [
143
                'timestamps' => $this->getResque()->getDelayedJobTimestamps()
144
            ]
145
        );
146
    }
147
148
    /**
149
     * @param $timestamp
150
     * @return Response
151
     */
152
    public function showTimestampAction($timestamp)
153
    {
154
        $jobs = [];
155
156
        // we don't want to enable the twig debug extension for this...
157
        foreach ($this->getResque()->getJobsForTimestamp($timestamp) as $job) {
158
            $jobs[] = print_r($job, TRUE);
159
        }
160
161
        return $this->render(
162
            'ResqueBundle:Default:scheduled_timestamp.html.twig',
163
            [
164
                'timestamp' => $timestamp,
165
                'jobs'      => $jobs
166
            ]
167
        );
168
    }
169
}
170