Skip to content

Commit

Permalink
Retrieve applications from provider in pulse connections recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Wycisk committed May 10, 2024
1 parent f0cee42 commit cd2e91f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
22 changes: 22 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function __construct(
protected int $pingInterval,
protected array $allowedOrigins,
protected int $maxMessageSize,
protected array $options = [],
) {
//
}
Expand Down Expand Up @@ -67,4 +68,25 @@ public function maxMessageSize(): int
{
return $this->maxMessageSize;
}

/**
* Get the application options.
*/
public function options(): ?array
{
return $this->options;
}

public function toArray(): array
{
return [
'app_id' => $this->id,
'key' => $this->key,
'secret' => $this->secret,
'ping_interval' => $this->pingInterval,
'allowed_origins' => $this->allowedOrigins,
'max_message_size' => $this->maxMessageSize,
'options' => $this->options,
];
}
}
1 change: 1 addition & 0 deletions src/ConfigApplicationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function find(string $key, mixed $value): Application
$app['ping_interval'],
$app['allowed_origins'],
$app['max_message_size'],
$app['options'],
);
}
}
30 changes: 17 additions & 13 deletions src/Pulse/Recorders/ReverbConnections.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use Illuminate\Broadcasting\BroadcastManager;
use Illuminate\Config\Repository;
use Illuminate\Contracts\Foundation\Application as Container;
use Laravel\Pulse\Events\IsolatedBeat;
use Laravel\Pulse\Pulse;
use Laravel\Pulse\Recorders\Concerns\Sampling;
use Laravel\Reverb\Application;
use Laravel\Reverb\Contracts\ApplicationProvider;

class ReverbConnections
{
Expand All @@ -25,7 +28,7 @@ class ReverbConnections
public function __construct(
protected Pulse $pulse,
protected BroadcastManager $broadcast,
protected Repository $config,
protected Container $app,
) {
//
}
Expand All @@ -39,17 +42,18 @@ public function record(IsolatedBeat $event): void
return;
}

foreach ($this->config->get('reverb.apps.apps') as $app) {
$connections = $this->broadcast->pusher($app)
->get('/connections')
->connections;

$this->pulse->record(
type: 'reverb_connections',
key: $app['app_id'],
value: $connections,
timestamp: $event->time->getTimestamp(),
)->avg()->max()->onlyBuckets();
}
$this->app->make(ApplicationProvider::class)->all()
->each(function (Application $app) use ($event) {
$connections = $this->broadcast->pusher($app->toArray())
->get('/connections')
->connections;

$this->pulse->record(
type: 'reverb_connections',
key: $app['app_id'],
value: $connections,
timestamp: $event->time->getTimestamp(),
)->avg()->max()->onlyBuckets();
});
}
}

0 comments on commit cd2e91f

Please sign in to comment.