55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\InventorySyncRun;
|
|
use App\Models\Tenant;
|
|
use App\Services\Drift\DriftFindingGenerator;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use RuntimeException;
|
|
|
|
class GenerateDriftFindingsJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public function __construct(
|
|
public int $tenantId,
|
|
public int $userId,
|
|
public int $baselineRunId,
|
|
public int $currentRunId,
|
|
public string $scopeKey,
|
|
) {}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*/
|
|
public function handle(DriftFindingGenerator $generator): void
|
|
{
|
|
$tenant = Tenant::query()->find($this->tenantId);
|
|
if (! $tenant instanceof Tenant) {
|
|
throw new RuntimeException('Tenant not found.');
|
|
}
|
|
|
|
$baseline = InventorySyncRun::query()->find($this->baselineRunId);
|
|
if (! $baseline instanceof InventorySyncRun) {
|
|
throw new RuntimeException('Baseline run not found.');
|
|
}
|
|
|
|
$current = InventorySyncRun::query()->find($this->currentRunId);
|
|
if (! $current instanceof InventorySyncRun) {
|
|
throw new RuntimeException('Current run not found.');
|
|
}
|
|
|
|
$generator->generate(
|
|
tenant: $tenant,
|
|
baseline: $baseline,
|
|
current: $current,
|
|
scopeKey: $this->scopeKey,
|
|
);
|
|
}
|
|
}
|