50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Symfony\Component\Process\Process;
|
|
|
|
class DeployStaticSiteJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public string $siteName;
|
|
public string $siteHost;
|
|
|
|
public string $siteId;
|
|
public function __construct(string $siteName, string $siteHost, string $siteId)
|
|
{
|
|
$this->siteName = $siteName;
|
|
$this->siteHost = $siteHost;
|
|
$this->siteId = $siteId;
|
|
}
|
|
|
|
public function handle(): void
|
|
{
|
|
// Run the deployment command (which already handles Ansible)
|
|
$exitCode = Artisan::call('deploy:static-site', [
|
|
'name' => $this->siteName,
|
|
'host' => $this->siteHost,
|
|
'id' => $this->siteId,
|
|
]);
|
|
|
|
if ($exitCode !== 0) {
|
|
$output = Artisan::output(); // optional: capture for logs
|
|
logger()->error("❌ deploy:static-site failed for {$this->siteName}", [
|
|
'output' => $output,
|
|
'exit_code' => $exitCode,
|
|
]);
|
|
|
|
throw new \RuntimeException("deploy:static-site failed with exit code $exitCode");
|
|
}
|
|
|
|
logger()->info("✅ deploy:static-site successful for {$this->siteName}");
|
|
}
|
|
}
|