Skip to content

Commit c6270bd

Browse files
authored
Merge pull request #58 from M6Web/fix/console-terminate
Send last statsd data on console.terminate
2 parents e01338e + d7d542c commit c6270bd

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/DependencyInjection/M6WebStatsdExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ protected function loadClient($container, $alias, array $config, array $servers,
178178
'method' => 'onKernelTerminate',
179179
'priority' => -100
180180
]);
181+
$definition->addTag('kernel.event_listener', [
182+
'event' => 'console.terminate',
183+
'method' => 'onConsoleTerminate',
184+
'priority' => -100
185+
]);
181186

182187
if ($baseEvents) {
183188
$definition->addTag('kernel.event_listener', [

src/Statsd/Listener.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace M6Web\Bundle\StatsdBundle\Statsd;
44

5+
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
56
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
67
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
78
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
@@ -59,6 +60,18 @@ public function onKernelTerminate(PostResponseEvent $event)
5960
$this->statsdClient->send();
6061
}
6162

63+
/**
64+
* method called on the console.terminate event
65+
*
66+
* @param ConsoleTerminateEvent $event event
67+
*
68+
* @return void
69+
*/
70+
public function onConsoleTerminate(ConsoleTerminateEvent $event)
71+
{
72+
$this->statsdClient->send();
73+
}
74+
6275
/**
6376
* method called if base_collectors = true in config to dispatch base events
6477
* (you still have to catch them)

0 commit comments

Comments
 (0)