96 lines
2.6 KiB
PHP
96 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Jobs\ScrapingDataJob;
|
|
use App\Models\ImportDatasource;
|
|
use App\Services\ServiceGoogleSheet;
|
|
use App\Services\ServicePbgTask;
|
|
use App\Services\ServiceTabPbgTask;
|
|
use App\Services\ServiceTokenSIMBG;
|
|
use GuzzleHttp\Client; // Import Guzzle Client
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ScrapingData extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'app:scraping-data';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Command description';
|
|
/**
|
|
* Inject dependencies.
|
|
*/
|
|
public function __construct(
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
dispatch(new ScrapingDataJob());
|
|
|
|
$this->info("Scraping job dispatched successfully");
|
|
}
|
|
|
|
/**
|
|
* 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',
|
|
// 'start_time' => now()
|
|
// ]);
|
|
|
|
// // 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.',
|
|
// 'finish_time' => now()
|
|
// ]);
|
|
|
|
// } 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(),
|
|
// 'finish_time' => now()
|
|
// ]);
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
|
|
}
|