diff --git a/src/Console/Commands/StaticWarm.php b/src/Console/Commands/StaticWarm.php index 87526b1254..e5a21a9e1f 100644 --- a/src/Console/Commands/StaticWarm.php +++ b/src/Console/Commands/StaticWarm.php @@ -74,12 +74,7 @@ public function handle() private function warm(): void { - $client = new Client([ - 'verify' => $this->shouldVerifySsl(), - 'auth' => $this->option('user') && $this->option('password') - ? [$this->option('user'), $this->option('password')] - : null, - ]); + $client = new Client($this->clientConfig()); $this->output->newLine(); $this->line('Compiling URLs...'); @@ -93,7 +88,7 @@ private function warm(): void $this->line(sprintf('Adding %s requests onto %squeue...', count($requests), $queue ? $queue.' ' : '')); foreach ($requests as $request) { - StaticWarmJob::dispatch($request)->onQueue($queue); + StaticWarmJob::dispatch($request, $this->clientConfig())->onQueue($queue); } } else { $this->line('Visiting '.count($requests).' URLs...'); @@ -117,6 +112,16 @@ private function concurrency(): int return config("statamic.static_caching.strategies.$strategy.warm_concurrency", 25); } + private function clientConfig(): array + { + return [ + 'verify' => $this->shouldVerifySsl(), + 'auth' => $this->option('user') && $this->option('password') + ? [$this->option('user'), $this->option('password')] + : null, + ]; + } + public function outputSuccessLine(Response $response, $index): void { $this->components->twoColumnDetail($this->getRelativeUri($index), '✓ Cached'); diff --git a/src/Console/Commands/StaticWarmJob.php b/src/Console/Commands/StaticWarmJob.php index e9cd038040..1db3c87fd0 100644 --- a/src/Console/Commands/StaticWarmJob.php +++ b/src/Console/Commands/StaticWarmJob.php @@ -13,17 +13,14 @@ class StaticWarmJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable; - public Request $request; - public $tries = 1; - public function __construct(Request $request) + public function __construct(public Request $request, public array $clientConfig) { - $this->request = $request; } - public function handle(Client $client) + public function handle() { - $client->send($this->request); + (new Client($this->clientConfig))->send($this->request); } } diff --git a/tests/Console/Commands/StaticWarmJobTest.php b/tests/Console/Commands/StaticWarmJobTest.php index ae316bba6e..b92c0e2941 100644 --- a/tests/Console/Commands/StaticWarmJobTest.php +++ b/tests/Console/Commands/StaticWarmJobTest.php @@ -2,7 +2,6 @@ namespace Tests\Console\Commands; -use GuzzleHttp\Client; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Request; @@ -22,11 +21,9 @@ public function it_sends_a_get_request() $handlerStack = HandlerStack::create($mock); - $client = new Client(['handler' => $handlerStack]); + $job = new StaticWarmJob(new Request('GET', '/about'), ['handler' => $handlerStack]); - $job = new StaticWarmJob(new Request('GET', '/about')); - - $job->handle($client); + $job->handle(); $this->assertEquals('/about', $mock->getLastRequest()->getUri()->getPath()); }