diff --git a/src/Console/ContinueCommand.php b/src/Console/ContinueCommand.php index 3f4ed3b9..5c2a5c2e 100644 --- a/src/Console/ContinueCommand.php +++ b/src/Console/ContinueCommand.php @@ -30,7 +30,7 @@ class ContinueCommand extends Command */ public function handle() { - $masters = resolve(MasterSupervisorRepository::class)->all(); + $masters = app(MasterSupervisorRepository::class)->all(); $masters = collect($masters)->filter(function ($master) { return Str::startsWith($master->name, MasterSupervisor::basename()); diff --git a/src/Console/HorizonCommand.php b/src/Console/HorizonCommand.php index 82ec3f41..2e02a0c2 100644 --- a/src/Console/HorizonCommand.php +++ b/src/Console/HorizonCommand.php @@ -37,7 +37,7 @@ class HorizonCommand extends Command */ public function handle() { - $repository = resolve(MasterSupervisorRepository::class); + $repository = app(MasterSupervisorRepository::class); if ($repository->find(MasterSupervisor::name())) { return $this->comment('A master supervisor is already running on this machine.'); diff --git a/src/Console/ListCommand.php b/src/Console/ListCommand.php index 1f212fcc..64f8472a 100644 --- a/src/Console/ListCommand.php +++ b/src/Console/ListCommand.php @@ -28,7 +28,7 @@ class ListCommand extends Command */ public function handle() { - $repository = resolve(MasterSupervisorRepository::class); + $repository = app(MasterSupervisorRepository::class); $masters = $repository->all(); diff --git a/src/Console/PauseCommand.php b/src/Console/PauseCommand.php index 06682e02..5607dd8f 100644 --- a/src/Console/PauseCommand.php +++ b/src/Console/PauseCommand.php @@ -30,7 +30,7 @@ class PauseCommand extends Command */ public function handle() { - $masters = resolve(MasterSupervisorRepository::class)->all(); + $masters = app(MasterSupervisorRepository::class)->all(); $masters = collect($masters)->filter(function ($master) { return Str::startsWith($master->name, MasterSupervisor::basename()); diff --git a/src/Console/PurgeCommand.php b/src/Console/PurgeCommand.php index 7c96d651..b404f08d 100644 --- a/src/Console/PurgeCommand.php +++ b/src/Console/PurgeCommand.php @@ -82,7 +82,7 @@ public function purge($master, protected function recordOrphans($master, ProcessRepository $processes) { $processes->orphaned( - $master, $orphans = resolve(ProcessInspector::class)->orphaned() + $master, $orphans = app(ProcessInspector::class)->orphaned() ); foreach ($orphans as $processId) { diff --git a/src/Console/SnapshotCommand.php b/src/Console/SnapshotCommand.php index 7dd6248b..89151f7c 100644 --- a/src/Console/SnapshotCommand.php +++ b/src/Console/SnapshotCommand.php @@ -29,8 +29,8 @@ class SnapshotCommand extends Command */ public function handle() { - if (resolve(Lock::class)->get('metrics:snapshot', 300)) { - resolve(MetricsRepository::class)->snapshot(); + if (app(Lock::class)->get('metrics:snapshot', 300)) { + app(MetricsRepository::class)->snapshot(); $this->info('Metrics snapshot stored successfully.'); } diff --git a/src/Console/SupervisorCommand.php b/src/Console/SupervisorCommand.php index 836501ad..84fcd6c5 100644 --- a/src/Console/SupervisorCommand.php +++ b/src/Console/SupervisorCommand.php @@ -50,7 +50,7 @@ class SupervisorCommand extends Command */ public function handle() { - $supervisor = resolve(SupervisorFactory::class)->make( + $supervisor = app(SupervisorFactory::class)->make( $this->supervisorOptions() ); diff --git a/src/Console/SupervisorsCommand.php b/src/Console/SupervisorsCommand.php index acabb369..a142bd2c 100644 --- a/src/Console/SupervisorsCommand.php +++ b/src/Console/SupervisorsCommand.php @@ -28,7 +28,7 @@ class SupervisorsCommand extends Command */ public function handle() { - $repository = resolve(SupervisorRepository::class); + $repository = app(SupervisorRepository::class); $supervisors = $repository->all(); diff --git a/src/Console/TerminateCommand.php b/src/Console/TerminateCommand.php index d80c99d1..03af8c9d 100644 --- a/src/Console/TerminateCommand.php +++ b/src/Console/TerminateCommand.php @@ -30,7 +30,7 @@ class TerminateCommand extends Command */ public function handle() { - $masters = resolve(MasterSupervisorRepository::class)->all(); + $masters = app(MasterSupervisorRepository::class)->all(); $masters = collect($masters)->filter(function ($master) { return Str::startsWith($master->name, MasterSupervisor::basename()); diff --git a/src/Http/Controllers/DashboardStatsController.php b/src/Http/Controllers/DashboardStatsController.php index 79cfed64..d0762905 100644 --- a/src/Http/Controllers/DashboardStatsController.php +++ b/src/Http/Controllers/DashboardStatsController.php @@ -18,14 +18,14 @@ class DashboardStatsController extends Controller public function index() { return [ - 'jobsPerMinute' => resolve(MetricsRepository::class)->jobsProcessedPerMinute(), + 'jobsPerMinute' => app(MetricsRepository::class)->jobsProcessedPerMinute(), 'processes' => $this->totalProcessCount(), - 'queueWithMaxRuntime' => resolve(MetricsRepository::class)->queueWithMaximumRuntime(), - 'queueWithMaxThroughput' => resolve(MetricsRepository::class)->queueWithMaximumThroughput(), - 'recentlyFailed' => resolve(JobRepository::class)->countRecentlyFailed(), - 'recentJobs' => resolve(JobRepository::class)->countRecent(), + 'queueWithMaxRuntime' => app(MetricsRepository::class)->queueWithMaximumRuntime(), + 'queueWithMaxThroughput' => app(MetricsRepository::class)->queueWithMaximumThroughput(), + 'recentlyFailed' => app(JobRepository::class)->countRecentlyFailed(), + 'recentJobs' => app(JobRepository::class)->countRecent(), 'status' => $this->currentStatus(), - 'wait' => collect(resolve(WaitTimeCalculator::class)->calculate())->take(1), + 'wait' => collect(app(WaitTimeCalculator::class)->calculate())->take(1), ]; } @@ -36,7 +36,7 @@ public function index() */ protected function totalProcessCount() { - $supervisors = resolve(SupervisorRepository::class)->all(); + $supervisors = app(SupervisorRepository::class)->all(); return collect($supervisors)->reduce(function ($carry, $supervisor) { return $carry + collect($supervisor->processes)->sum(); @@ -50,7 +50,7 @@ protected function totalProcessCount() */ protected function currentStatus() { - if (! $masters = resolve(MasterSupervisorRepository::class)->all()) { + if (! $masters = app(MasterSupervisorRepository::class)->all()) { return 'inactive'; } diff --git a/src/JobId.php b/src/JobId.php index f0badc62..737983c3 100644 --- a/src/JobId.php +++ b/src/JobId.php @@ -24,7 +24,7 @@ public static function generate() return call_user_func(static::$generator); } - return resolve(JobRepository::class)->nextJobId(); + return app(JobRepository::class)->nextJobId(); } /** diff --git a/src/Listeners/ExpireSupervisors.php b/src/Listeners/ExpireSupervisors.php index da44451d..5e838f8d 100644 --- a/src/Listeners/ExpireSupervisors.php +++ b/src/Listeners/ExpireSupervisors.php @@ -17,8 +17,8 @@ class ExpireSupervisors */ public function handle(MasterSupervisorLooped $event) { - resolve(MasterSupervisorRepository::class)->flushExpired(); + app(MasterSupervisorRepository::class)->flushExpired(); - resolve(SupervisorRepository::class)->flushExpired(); + app(SupervisorRepository::class)->flushExpired(); } } diff --git a/src/Listeners/MonitorWaitTimes.php b/src/Listeners/MonitorWaitTimes.php index b88fe647..8375ae7b 100644 --- a/src/Listeners/MonitorWaitTimes.php +++ b/src/Listeners/MonitorWaitTimes.php @@ -50,7 +50,7 @@ public function handle(SupervisorLooped $event) // Here we will calculate the wait time in seconds for each of the queues that // the application is working. Then, we will filter the results to find the // queues with the longest wait times and raise events for each of these. - $results = resolve(WaitTimeCalculator::class)->calculate(); + $results = app(WaitTimeCalculator::class)->calculate(); $long = collect($results)->filter(function ($wait, $queue) { return $wait > (config("horizon.waits.{$queue}") ?? 60); diff --git a/src/Listeners/SendNotification.php b/src/Listeners/SendNotification.php index cf39c2a4..962054d1 100644 --- a/src/Listeners/SendNotification.php +++ b/src/Listeners/SendNotification.php @@ -18,7 +18,7 @@ public function handle($event) { $notification = $event->toNotification(); - if (! resolve(Lock::class)->get('notification:'.$notification->signature(), 300)) { + if (! app(Lock::class)->get('notification:'.$notification->signature(), 300)) { return; } diff --git a/src/Listeners/TrimFailedJobs.php b/src/Listeners/TrimFailedJobs.php index 714b9f4f..13d3cc02 100644 --- a/src/Listeners/TrimFailedJobs.php +++ b/src/Listeners/TrimFailedJobs.php @@ -39,7 +39,7 @@ public function handle(MasterSupervisorLooped $event) } if ($this->lastTrimmed->lte(Chronos::now()->subMinutes($this->frequency))) { - resolve(JobRepository::class)->trimFailedJobs(); + app(JobRepository::class)->trimFailedJobs(); $this->lastTrimmed = Chronos::now(); } diff --git a/src/Listeners/TrimRecentJobs.php b/src/Listeners/TrimRecentJobs.php index 17d453b1..73366334 100644 --- a/src/Listeners/TrimRecentJobs.php +++ b/src/Listeners/TrimRecentJobs.php @@ -39,7 +39,7 @@ public function handle(MasterSupervisorLooped $event) } if ($this->lastTrimmed->lte(Chronos::now()->subMinutes($this->frequency))) { - resolve(JobRepository::class)->trimRecentJobs(); + app(JobRepository::class)->trimRecentJobs(); $this->lastTrimmed = Chronos::now(); } diff --git a/src/MasterSupervisor.php b/src/MasterSupervisor.php index 4bc41492..26831d5d 100644 --- a/src/MasterSupervisor.php +++ b/src/MasterSupervisor.php @@ -68,7 +68,7 @@ public function __construct() // }; - resolve(HorizonCommandQueue::class)->flush($this->commandQueue()); + app(HorizonCommandQueue::class)->flush($this->commandQueue()); } /** @@ -161,13 +161,13 @@ public function terminate($status = 0) // active supervisors so we know the maximum amount of time to wait here. $this->supervisors->each->terminate(); - $longest = resolve(SupervisorRepository::class) + $longest = app(SupervisorRepository::class) ->longestActiveTimeout(); // We will go ahead and remove this master supervisor's record from storage so // another master supervisor could get started in its place without waiting // for it to really finish terminating all of its underlying supervisors. - resolve(MasterSupervisorRepository::class) + app(MasterSupervisorRepository::class) ->forget($this->name); $startedTerminating = Chronos::now(); @@ -215,7 +215,7 @@ public function monitor() */ public function ensureNoOtherMasterSupervisors() { - if (resolve(MasterSupervisorRepository::class)->find($this->name) !== null) { + if (app(MasterSupervisorRepository::class)->find($this->name) !== null) { throw new Exception('A master supervisor is already running on this machine.'); } } @@ -238,9 +238,9 @@ public function loop() event(new MasterSupervisorLooped($this)); } catch (Exception $e) { - resolve(ExceptionHandler::class)->report($e); + app(ExceptionHandler::class)->report($e); } catch (Throwable $e) { - resolve(ExceptionHandler::class)->report(new FatalThrowableError($e)); + app(ExceptionHandler::class)->report(new FatalThrowableError($e)); } } @@ -251,8 +251,8 @@ public function loop() */ protected function processPendingCommands() { - foreach (resolve(HorizonCommandQueue::class)->pending($this->commandQueue()) as $command) { - resolve($command->command)->process($this, $command->options); + foreach (app(HorizonCommandQueue::class)->pending($this->commandQueue()) as $command) { + app($command->command)->process($this, $command->options); } } @@ -275,7 +275,7 @@ protected function monitorSupervisors() */ public function persist() { - resolve(MasterSupervisorRepository::class)->update($this); + app(MasterSupervisorRepository::class)->update($this); } /** diff --git a/src/ProcessInspector.php b/src/ProcessInspector.php index 29fd687c..8bf47d8e 100644 --- a/src/ProcessInspector.php +++ b/src/ProcessInspector.php @@ -55,7 +55,7 @@ public function orphaned() */ public function monitoring() { - return collect(resolve(SupervisorRepository::class)->all()) + return collect(app(SupervisorRepository::class)->all()) ->pluck('pid') ->pipe(function ($processes) { $processes->each(function ($process) use (&$processes) { @@ -65,7 +65,7 @@ public function monitoring() return $processes; }) ->merge( - array_pluck(resolve(MasterSupervisorRepository::class)->all(), 'pid') + array_pluck(app(MasterSupervisorRepository::class)->all(), 'pid') )->all(); } } diff --git a/src/ProvisioningPlan.php b/src/ProvisioningPlan.php index 750c9a19..1b6f4b84 100644 --- a/src/ProvisioningPlan.php +++ b/src/ProvisioningPlan.php @@ -106,7 +106,7 @@ public function deploy($environment) */ protected function add(SupervisorOptions $options) { - resolve(HorizonCommandQueue::class)->push( + app(HorizonCommandQueue::class)->push( MasterSupervisor::commandQueueFor($this->master), AddSupervisor::class, $options->toArray() diff --git a/src/Repositories/RedisMasterSupervisorRepository.php b/src/Repositories/RedisMasterSupervisorRepository.php index 49b3ea1f..31792a0d 100644 --- a/src/Repositories/RedisMasterSupervisorRepository.php +++ b/src/Repositories/RedisMasterSupervisorRepository.php @@ -128,7 +128,7 @@ public function forget($name) return; } - resolve(SupervisorRepository::class)->forget( + app(SupervisorRepository::class)->forget( $master->supervisors ); diff --git a/src/Repositories/RedisMetricsRepository.php b/src/Repositories/RedisMetricsRepository.php index 9e9daf5d..d08e2fb7 100644 --- a/src/Repositories/RedisMetricsRepository.php +++ b/src/Repositories/RedisMetricsRepository.php @@ -292,7 +292,7 @@ protected function storeSnapshotForQueue($queue) 'snapshot:'.$key, $time = Chronos::now()->getTimestamp(), json_encode([ 'throughput' => $data['throughput'], 'runtime' => $data['runtime'], - 'wait' => resolve(WaitTimeCalculator::class)->calculateFor($queue), + 'wait' => app(WaitTimeCalculator::class)->calculateFor($queue), 'time' => $time, ]) ); @@ -358,7 +358,7 @@ protected function storeSnapshotTimestamp() */ public function acquireWaitTimeMonitorLock() { - return resolve(Lock::class)->get('monitor:time-to-clear'); + return app(Lock::class)->get('monitor:time-to-clear'); } /** diff --git a/src/Supervisor.php b/src/Supervisor.php index 92d44d69..fd8be4d2 100644 --- a/src/Supervisor.php +++ b/src/Supervisor.php @@ -82,7 +82,7 @@ public function __construct(SupervisorOptions $options) // }; - resolve(HorizonCommandQueue::class)->flush($this->name); + app(HorizonCommandQueue::class)->flush($this->name); } /** @@ -217,7 +217,7 @@ public function terminate($status = 0) // We will mark this supervisor as terminating so that any user interface can // correctly show the supervisor's status. Then, we will scale the process // pools down to zero workers to gracefully terminate them all out here. - resolve(SupervisorRepository::class) + app(SupervisorRepository::class) ->forget($this->name); $this->processPools->each->scale(0); @@ -260,7 +260,7 @@ public function monitor() */ public function ensureNoDuplicateSupervisors() { - if (resolve(SupervisorRepository::class)->find($this->name) !== null) { + if (app(SupervisorRepository::class)->find($this->name) !== null) { throw new Exception("A supervisor with the name [{$this->name}] is already running."); } } @@ -291,9 +291,9 @@ public function loop() event(new SupervisorLooped($this)); } catch (Exception $e) { - resolve(ExceptionHandler::class)->report($e); + app(ExceptionHandler::class)->report($e); } catch (Throwable $e) { - resolve(ExceptionHandler::class)->report(new FatalThrowableError($e)); + app(ExceptionHandler::class)->report(new FatalThrowableError($e)); } } @@ -304,8 +304,8 @@ public function loop() */ protected function processPendingCommands() { - foreach (resolve(HorizonCommandQueue::class)->pending($this->name) as $command) { - resolve($command->command)->process($this, $command->options); + foreach (app(HorizonCommandQueue::class)->pending($this->name) as $command) { + app($command->command)->process($this, $command->options); } } @@ -322,7 +322,7 @@ protected function autoScale() if (Chronos::now()->subSeconds($this->autoScaleCooldown)->gte($this->lastAutoScaled)) { $this->lastAutoScaled = Chronos::now(); - resolve(AutoScaler::class)->scale($this); + app(AutoScaler::class)->scale($this); } } @@ -333,7 +333,7 @@ protected function autoScale() */ public function persist() { - resolve(SupervisorRepository::class)->update($this); + app(SupervisorRepository::class)->update($this); } /** @@ -395,7 +395,7 @@ public function totalProcessCount() */ public function totalSystemProcessCount() { - return resolve(SystemProcessCounter::class)->get($this->name); + return app(SystemProcessCounter::class)->get($this->name); } /** diff --git a/src/SupervisorProcess.php b/src/SupervisorProcess.php index e373284e..872b05c0 100644 --- a/src/SupervisorProcess.php +++ b/src/SupervisorProcess.php @@ -112,7 +112,7 @@ public function monitor() */ protected function reprovision() { - resolve(HorizonCommandQueue::class)->push( + app(HorizonCommandQueue::class)->push( MasterSupervisor::commandQueue(), AddSupervisor::class, $this->options->toArray() @@ -127,7 +127,7 @@ protected function reprovision() */ public function terminateWithStatus($status) { - resolve(HorizonCommandQueue::class)->push( + app(HorizonCommandQueue::class)->push( $this->options->name, Terminate::class, ['status' => $status] ); }