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