1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mpclarkson\ResqueBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Mpclarkson\ResqueBundle\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 Mpclarkson\ResqueBundle\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
|
|
|
|