Completed
Push — master ( f5ce61...9abbfe )
by Phil
03:10
created

DefaultController::retryFailedAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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
    /**
171
     * @return RedirectResponse
172
     */
173 View Code Duplication
    public function retryFailedAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
174
    {
175
        $count = $this->getResque()->retryFailedJobs();
176
177
        $this->addFlash('info', 'Retry '.$count.' failed jobs.');
178
179
        return $this->redirectToRoute('ResqueBundle_homepage');
180
    }
181
182
    /**
183
     * @return RedirectResponse
184
     */
185 View Code Duplication
    public function clearFailedAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
186
    {
187
        $count = $this->getResque()->clearFailedJobs();
188
189
        $this->addFlash('info', 'Clear '.$count.' failed jobs.');
190
191
        return $this->redirectToRoute('ResqueBundle_homepage');
192
    }
193
}
194