Moved the create record into a separate method.

This commit is contained in:
Alex Renoki 2020-08-30 20:07:24 +03:00
parent aa014add21
commit 1923ceedea
2 changed files with 29 additions and 7 deletions

View File

@ -103,7 +103,7 @@ class MemoryStatisticsLogger implements StatisticsLogger
continue; continue;
} }
$this->driver::create($statistic->toArray()); $this->createRecord($statistic);
$currentConnectionCount = $this->channelManager->getConnectionCount($appId); $currentConnectionCount = $this->channelManager->getConnectionCount($appId);
@ -135,4 +135,15 @@ class MemoryStatisticsLogger implements StatisticsLogger
{ {
return $this->statistics; return $this->statistics;
} }
/**
* Create a new record using the Statistic Driver.
*
* @param Statistic $statistic
* @return void
*/
public function createRecord(Statistic $statistic)
{
$this->driver::create($statistic->toArray());
}
} }

View File

@ -122,12 +122,7 @@ class RedisStatisticsLogger implements StatisticsLogger
continue; continue;
} }
$this->driver::create([ $this->createRecord($statistic);
'app_id' => $appId,
'peak_connection_count' => $statistic['peak_connection_count'] ?? 0,
'websocket_message_count' => $statistic['websocket_message_count'] ?? 0,
'api_message_count' => $statistic['api_message_count'] ?? 0,
]);
$currentConnectionCount = $this->channelManager->getConnectionCount($appId); $currentConnectionCount = $this->channelManager->getConnectionCount($appId);
@ -203,4 +198,20 @@ class RedisStatisticsLogger implements StatisticsLogger
{ {
return new RedisLock($this->redis, 'laravel-websockets:lock', 0); return new RedisLock($this->redis, 'laravel-websockets:lock', 0);
} }
/**
* Create a new record using the Statistic Driver.
*
* @param array $statistic
* @return void
*/
protected function createRecord(array $statistic): void
{
$this->driver::create([
'app_id' => $appId,
'peak_connection_count' => $statistic['peak_connection_count'] ?? 0,
'websocket_message_count' => $statistic['websocket_message_count'] ?? 0,
'api_message_count' => $statistic['api_message_count'] ?? 0,
]);
}
} }