This commit is contained in:
freek 2018-12-03 16:50:06 +01:00
parent b6b1d220ff
commit ff7953404f
3 changed files with 19 additions and 7 deletions

View File

@ -58,7 +58,8 @@ class StartWebSocketServer extends Command
return new HttpStatisticsLogger(app(ChannelManager::class), $client); return new HttpStatisticsLogger(app(ChannelManager::class), $client);
}); });
$this->loop->addPeriodicTimer(60, function() { $this->loop->addPeriodicTimer(5, function() {
echo 'saving stats...';
StatisticsLogger::save($this->loop); StatisticsLogger::save($this->loop);
}); });

View File

@ -3,7 +3,6 @@
namespace BeyondCode\LaravelWebSockets\Statistics\Http\Controllers; namespace BeyondCode\LaravelWebSockets\Statistics\Http\Controllers;
use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId; use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId;
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class WebsocketStatisticsEntriesController class WebsocketStatisticsEntriesController

View File

@ -60,15 +60,27 @@ class HttpStatisticsLogger implements StatisticsLogger
public function save() public function save()
{ {
echo 'in actual save method';
foreach ($this->statistics as $appId => $statistic) { foreach ($this->statistics as $appId => $statistic) {
if (! $statistic->isEnabled()) { echo "stats of ${appId} " . $statistic->isEnabled() ? 'enabled' : 'DISABLED!';
if (!$statistic->isEnabled()) {
continue; continue;
} }
$this->client->postAsync( echo 'posted';
$this->client
->postAsync(
action([WebsocketStatisticsEntriesController::class, 'store']), action([WebsocketStatisticsEntriesController::class, 'store']),
$statistic->toArray() $statistic->toArray()
); )
->then(function() {
echo 'fulfilled';
})
->otherwise(function() {
echo 'rejected!';
var_dump(func_get_args());
});
// Reset connection and message count // Reset connection and message count
$currentConnectionCount = collect($this->channelManager->getChannels($appId)) $currentConnectionCount = collect($this->channelManager->getChannels($appId))