Skip to content

Commit

Permalink
fix(provider): Fix instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver committed Jan 18, 2023
1 parent d421275 commit d7bb64e
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/HorizonTelemetryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,32 @@
use Worksome\HorizonTelemetry\Enums\MeterName;
use Worksome\HorizonTelemetry\Listeners\FailedJobsListener;
use Worksome\HorizonTelemetry\Listeners\ProcessedJobsListener;
use Worksome\HorizonTelemetry\Metrics\CurrentJobsMetric;
use Worksome\HorizonTelemetry\Metrics\CurrentMasterSupervisorsMetric;
use Worksome\HorizonTelemetry\Metrics\CurrentProcessesMetric;
use Worksome\HorizonTelemetry\Metrics\CurrentJobsMetric;

class HorizonTelemetryServiceProvider extends ServiceProvider
{
private const CONFIG_PATH = __DIR__ . '/../config/telemetry.php';

private const CONFIG_PREFIX = 'telemetry.horizon.';

public function boot(Dispatcher $dispatcher, Repository $config): void
public function boot(): void
{
if ($config->get(self::CONFIG_PREFIX . MeterName::FailedJobs->value)) {
$dispatcher->listen(JobFailed::class, FailedJobsListener::class);
}
$this->callAfterResolving(Dispatcher::class, function (Dispatcher $dispatcher) {
/** @var Repository $config */
$config = $this->app->make(Repository::class);

if ($config->get(self::CONFIG_PREFIX . MeterName::ProcessedJobs->value)) {
$dispatcher->listen(JobProcessed::class, ProcessedJobsListener::class);
}
if ($config->get(self::CONFIG_PREFIX . MeterName::FailedJobs->value)) {
$dispatcher->listen(JobFailed::class, FailedJobsListener::class);
}

if ($config->get(self::CONFIG_PREFIX . MeterName::ProcessedJobs->value)) {
$dispatcher->listen(JobProcessed::class, ProcessedJobsListener::class);
}
});

$this->app->booted(function () {
/** @var Schedule $schedule */
$schedule = $this->app->make(Schedule::class);
$this->callAfterResolving(Schedule::class, function (Schedule $schedule) {
/** @var Repository $config */
$config = $this->app->make(Repository::class);

Expand Down

0 comments on commit d7bb64e

Please sign in to comment.