client = $client; $this->service_pbg_task = $service_pbg_task; $this->service_tab_pbg_task = $serviceTabPbgTask; } /** * Execute the console command. */ public function handle() { try { // Create a record with "processing" status $import_datasource = ImportDatasource::create([ 'message' => 'Initiating scraping...', 'response_body' => null, 'status' => 'processing' ]); // Run the service $service_google_sheet = new ServiceGoogleSheet(); $service_google_sheet->run_service(); // Run the ServicePbgTask with injected Guzzle Client $this->service_pbg_task->run_service(); // run the service pbg task assignments $this->service_tab_pbg_task->run_service(); // Update the record status to "success" after completion $import_datasource->update([ 'status' => 'success', 'message' => 'Scraping completed successfully.' ]); } catch (\Exception $e) { // Log the error for debugging Log::error('Scraping failed: ' . $e->getMessage(), ['trace' => $e->getTraceAsString()]); // Handle errors by updating the status to "failed" if (isset($import_datasource)) { $import_datasource->update([ 'status' => 'failed', 'response_body' => 'Error: ' . $e->getMessage() ]); } } } }