1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pyrowman\PheanstalkBundle\Listener; |
4
|
|
|
|
5
|
|
|
use Pyrowman\PheanstalkBundle\Event\CommandEvent; |
6
|
|
|
use Pyrowman\PheanstalkBundle\Proxy\PheanstalkProxyInterface; |
7
|
|
|
use Psr\Log\LoggerAwareTrait; |
8
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
9
|
|
|
|
10
|
|
|
class PheanstalkLogListener implements EventSubscriberInterface |
11
|
|
|
{ |
12
|
|
|
use LoggerAwareTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @inheritdoc |
16
|
|
|
*/ |
17
|
1 |
|
public static function getSubscribedEvents() |
18
|
|
|
{ |
19
|
|
|
return [ |
20
|
1 |
|
CommandEvent::DELETE => 'onCommand', |
21
|
|
|
CommandEvent::LIST_TUBES => 'onCommand', |
22
|
|
|
CommandEvent::LIST_WORKFLOWS => 'onCommand', |
23
|
|
|
CommandEvent::PEEK => 'onCommand', |
24
|
|
|
CommandEvent::PUT => 'onCommand', |
25
|
|
|
CommandEvent::STATS => 'onCommand', |
26
|
|
|
CommandEvent::STATS_TUBE => 'onCommand', |
27
|
|
|
CommandEvent::STATS_JOB => 'onCommand', |
28
|
|
|
CommandEvent::CREATE_TASK => 'onCommand', |
29
|
|
|
CommandEvent::CREATE_TUBE => 'onCommand', |
30
|
|
|
CommandEvent::CREATE_WORKFLOW => 'onCommand', |
31
|
|
|
CommandEvent::UPDATE_WORKFLOW => 'onCommand', |
32
|
|
|
CommandEvent::CREATE_WORKFLOW_SCHEDULER => 'onCommand', |
33
|
|
|
CommandEvent::WORKFLOW_EXISTS => 'onCommand', |
34
|
|
|
CommandEvent::WORKFLOW_INSTANCES => 'onCommand', |
35
|
|
|
CommandEvent::WORKFLOW_INSTANCES_DETAILS => 'onCommand', |
36
|
|
|
CommandEvent::TASK_EXISTS => 'onCommand', |
37
|
|
|
CommandEvent::TUBE_EXISTS => 'onCommand', |
38
|
|
|
CommandEvent::CANCEL => 'onCommand', |
39
|
|
|
CommandEvent::KILL => 'onCommand', |
40
|
|
|
CommandEvent::CREATE_SCHEDULE => 'onCommand', |
41
|
|
|
CommandEvent::UPDATE_SCHEDULE => 'onCommand', |
42
|
|
|
CommandEvent::LIST_SCHEDULE => 'onCommand', |
43
|
|
|
CommandEvent::DELETE_SCHEDULE => 'onCommand', |
44
|
|
|
CommandEvent::GET_SCHEDULE => 'onCommand', |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param CommandEvent $event |
50
|
|
|
* @param string $eventName |
51
|
|
|
*/ |
52
|
4 |
|
public function onCommand(CommandEvent $event, $eventName) |
53
|
|
|
{ |
54
|
4 |
|
if (!$this->logger) { |
55
|
1 |
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
3 |
|
$pheanstalk = $event->getPheanstalk(); |
59
|
3 |
|
$connection = $pheanstalk->getConnection(); |
60
|
|
|
|
61
|
3 |
|
if (!$connection->isServiceListening()) { |
62
|
1 |
|
$this->logger->warning('Pheanstalk connection isn\'t listening'); |
63
|
|
|
} |
64
|
|
|
|
65
|
3 |
|
$pheanstalkName = 'unknown'; |
66
|
3 |
|
if ($pheanstalk instanceof PheanstalkProxyInterface) { |
67
|
3 |
|
$pheanstalkName = $pheanstalk->getName(); |
68
|
|
|
} |
69
|
|
|
|
70
|
3 |
|
$nameExploded = explode('.', $eventName); |
71
|
|
|
|
72
|
3 |
|
$this->logger->info( |
73
|
3 |
|
'Pheanstalk command: '.$nameExploded[count($nameExploded) - 1], |
74
|
|
|
[ |
75
|
3 |
|
'payload' => $event->getPayload(), |
76
|
3 |
|
'pheanstalk' => $pheanstalkName, |
77
|
|
|
] |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|