Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit f04cce7

Browse files
committed
Added websockets:flush command
1 parent be9e21e commit f04cce7

File tree

4 files changed

+49
-20
lines changed

4 files changed

+49
-20
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace BeyondCode\LaravelWebSockets\Console\Commands;
4+
5+
use BeyondCode\LaravelWebSockets\Facades\StatisticsCollector;
6+
use Illuminate\Console\Command;
7+
8+
class FlushCollectedStatistics extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'websockets:flush';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string|null
21+
*/
22+
protected $description = 'Flush the collected statistics.';
23+
24+
/**
25+
* Run the command.
26+
*
27+
* @return void
28+
*/
29+
public function handle()
30+
{
31+
$this->comment('Flushing the collected WebSocket Statistics...');
32+
33+
StatisticsCollector::flush();
34+
35+
$this->line('Flush complete!');
36+
}
37+
}

src/Console/Commands/StartServer.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace BeyondCode\LaravelWebSockets\Console\Commands;
44

55
use BeyondCode\LaravelWebSockets\Contracts\ChannelManager;
6-
use BeyondCode\LaravelWebSockets\Contracts\StatisticsCollector;
76
use BeyondCode\LaravelWebSockets\Facades\StatisticsCollector as StatisticsCollectorFacade;
87
use BeyondCode\LaravelWebSockets\Facades\WebSocketRouter;
98
use BeyondCode\LaravelWebSockets\Server\Loggers\ConnectionLogger;
@@ -120,14 +119,6 @@ protected function configureManagers()
120119
*/
121120
protected function configureStatistics()
122121
{
123-
$this->laravel->singleton(StatisticsCollector::class, function () {
124-
$replicationMode = config('websockets.replication.mode', 'local');
125-
126-
$class = config("websockets.replication.modes.{$replicationMode}.collector");
127-
128-
return new $class;
129-
});
130-
131122
if (! $this->option('disable-statistics')) {
132123
$intervalInSeconds = $this->option('statistics-interval') ?: config('websockets.statistics.interval_in_seconds', 3600);
133124

src/WebSocketsServiceProvider.php

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

33
namespace BeyondCode\LaravelWebSockets;
44

5+
use BeyondCode\LaravelWebSockets\Contracts\StatisticsCollector;
56
use BeyondCode\LaravelWebSockets\Contracts\StatisticsStore;
67
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
78
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
@@ -65,6 +66,14 @@ protected function registerStatistics()
6566

6667
return new $class;
6768
});
69+
70+
$this->app->singleton(StatisticsCollector::class, function () {
71+
$replicationMode = config('websockets.replication.mode', 'local');
72+
73+
$class = config("websockets.replication.modes.{$replicationMode}.collector");
74+
75+
return new $class;
76+
});
6877
}
6978

7079
/**
@@ -91,6 +100,7 @@ protected function registerCommands()
91100
Console\Commands\StartServer::class,
92101
Console\Commands\RestartServer::class,
93102
Console\Commands\CleanStatistics::class,
103+
Console\Commands\FlushCollectedStatistics::class,
94104
]);
95105
}
96106

tests/TestCase.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,15 @@ protected function registerManagers()
222222
}
223223

224224
/**
225-
* Register the statistics collectors that are
226-
* not resolved by the package service provider.
225+
* Register the statistics collectors.
227226
*
228227
* @return void
229228
*/
230229
protected function registerStatisticsCollectors()
231230
{
232-
$this->app->singleton(StatisticsCollector::class, function () {
233-
$mode = config('websockets.replication.mode', $this->replicationMode);
234-
235-
$class = config("websockets.replication.modes.{$mode}.collector");
236-
237-
return new $class;
238-
});
239-
240231
$this->statisticsCollector = $this->app->make(StatisticsCollector::class);
241232

242-
$this->statisticsCollector->flush();
233+
$this->artisan('websockets:flush');
243234
}
244235

245236
/**

0 commit comments

Comments
 (0)