1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BrainExe\Core\Stats; |
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\RedisTrait; |
10
|
|
|
use Predis\PredisException; |
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @ControllerAnnotation("Stats.Controller") |
15
|
|
|
*/ |
16
|
|
|
class Controller |
17
|
|
|
{ |
18
|
|
|
use RedisTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var MessageQueueGateway |
22
|
|
|
*/ |
23
|
|
|
private $messageQueue; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var Stats |
27
|
|
|
*/ |
28
|
|
|
private $stats; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @Inject({"@Stats.Stats", "@MessageQueue.Gateway"}) |
32
|
|
|
* @param Stats $stats |
33
|
|
|
* @param MessageQueueGateway $gateway |
34
|
|
|
*/ |
35
|
3 |
|
public function __construct(Stats $stats, MessageQueueGateway $gateway) |
36
|
|
|
{ |
37
|
3 |
|
$this->messageQueue = $gateway; |
38
|
3 |
|
$this->stats = $stats; |
39
|
3 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @Route("/stats/", name="status.index") |
43
|
|
|
*/ |
44
|
2 |
|
public function index() : array |
45
|
|
|
{ |
46
|
2 |
|
$stats = $this->stats->getAll(); |
47
|
|
|
|
48
|
|
|
try { |
49
|
2 |
|
$redisStats = $this->getRedis()->info(); |
50
|
1 |
|
} catch (PredisException $e) { |
51
|
1 |
|
$redisStats = []; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return [ |
55
|
2 |
|
'jobs' => $this->messageQueue->getEventsByType(), |
56
|
2 |
|
'stats' => $stats, |
57
|
2 |
|
'redis' => $redisStats |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @Route("/stats/reset/", methods="POST", name="stats.reset") |
63
|
|
|
* @param Request $request |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
1 |
|
public function resetStats(Request $request) : bool |
67
|
|
|
{ |
68
|
1 |
|
$key = $request->request->get('key'); |
69
|
1 |
|
$this->stats->set([$key => 0]); |
70
|
|
|
|
71
|
1 |
|
return true; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|