$this->tenantId, 'baseline_run_id' => $this->baselineRunId, 'current_run_id' => $this->currentRunId, 'scope_key' => $this->scopeKey, 'bulk_operation_run_id' => $this->bulkOperationRunId, ]); $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.'); } $run = BulkOperationRun::query() ->where('tenant_id', $tenant->getKey()) ->find($this->bulkOperationRunId); if (! $run instanceof BulkOperationRun) { throw new RuntimeException('Bulk operation run not found.'); } $bulkOperationService->start($run); try { $created = $generator->generate( tenant: $tenant, baseline: $baseline, current: $current, scopeKey: $this->scopeKey, ); Log::info('GenerateDriftFindingsJob: completed', [ 'tenant_id' => $this->tenantId, 'baseline_run_id' => $this->baselineRunId, 'current_run_id' => $this->currentRunId, 'scope_key' => $this->scopeKey, 'bulk_operation_run_id' => $this->bulkOperationRunId, 'created_findings_count' => $created, ]); $bulkOperationService->recordSuccess($run); $bulkOperationService->complete($run); } catch (Throwable $e) { Log::error('GenerateDriftFindingsJob: failed', [ 'tenant_id' => $this->tenantId, 'baseline_run_id' => $this->baselineRunId, 'current_run_id' => $this->currentRunId, 'scope_key' => $this->scopeKey, 'bulk_operation_run_id' => $this->bulkOperationRunId, 'error' => $e->getMessage(), ]); $bulkOperationService->fail($run, $e->getMessage()); throw $e; } } }