1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BrainExe\Core\MessageQueue; |
4
|
|
|
|
5
|
|
|
use BrainExe\Annotations\Annotations\Inject; |
6
|
|
|
use BrainExe\Core\Annotations\Controller as ControllerAnnotation; |
7
|
|
|
use BrainExe\Core\Annotations\Route; |
8
|
|
|
use BrainExe\Core\MessageQueue\Gateway as MessageQueueGateway; |
9
|
|
|
use BrainExe\Core\Traits\EventDispatcherTrait; |
10
|
|
|
use BrainExe\Core\Traits\TimeTrait; |
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @ControllerAnnotation("MessageQueue.Controller") |
15
|
|
|
*/ |
16
|
|
|
class Controller |
17
|
|
|
{ |
18
|
|
|
use EventDispatcherTrait; |
19
|
|
|
use TimeTrait; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var MessageQueueGateway |
23
|
|
|
*/ |
24
|
|
|
private $gateway; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @Inject({"@MessageQueue.Gateway"}) |
28
|
|
|
* @param MessageQueueGateway $gateway |
29
|
|
|
*/ |
30
|
2 |
|
public function __construct(MessageQueueGateway $gateway) |
31
|
|
|
{ |
32
|
2 |
|
$this->gateway = $gateway; |
33
|
2 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @Route("/jobs/{type}/", name="status.jobs.type", methods="GET") |
37
|
|
|
* @param Request $request |
38
|
|
|
* @param string $type |
39
|
|
|
* @return Job[] |
40
|
|
|
*/ |
41
|
1 |
|
public function getJobs(Request $request, $type) |
42
|
|
|
{ |
43
|
1 |
|
$since = 0; |
44
|
|
|
|
45
|
1 |
|
if ($request->query->get('futureOnly')) { |
46
|
1 |
|
$since = $this->now(); |
47
|
|
|
} |
48
|
|
|
|
49
|
1 |
|
return $this->gateway->getEventsByType($type, $since); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @Route("/jobs/{jobId}/", methods="DELETE", name="messageQueue.deleteJob") |
54
|
|
|
* @param Request $request |
55
|
|
|
* @param $jobId |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
1 |
|
public function deleteJob(Request $request, $jobId) |
59
|
|
|
{ |
60
|
1 |
|
unset($request); |
61
|
|
|
|
62
|
1 |
|
$this->gateway->deleteEvent($jobId); |
63
|
|
|
|
64
|
1 |
|
return true; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|