importId, ['status' => 'processing'], now()->addDay()); try { $stats = $this->runSync($this->filePath); Cache::put($this->importId, [ 'status' => 'completed', 'stats' => $stats, ], now()->addDay()); } finally { $this->cleanupFile(); } } public function failed(Throwable $e): void { Cache::put($this->importId, [ 'status' => 'failed', 'message' => $e->getMessage(), ], now()->addDay()); $this->cleanupFile(); } abstract protected function runSync(string $filePath): array; private function cleanupFile(): void { Storage::delete($this->filePath); } }