fix syncronize using worker and add duration syncronize
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
|
||||
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;
|
||||
@@ -26,64 +28,68 @@ class ScrapingData extends Command
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
private $client;
|
||||
private $service_pbg_task;
|
||||
private $service_tab_pbg_task;
|
||||
|
||||
/**
|
||||
* Inject dependencies.
|
||||
*/
|
||||
public function __construct(Client $client, ServicePbgTask $service_pbg_task, ServiceTabPbgTask $serviceTabPbgTask)
|
||||
{
|
||||
public function __construct(
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->client = $client;
|
||||
$this->service_pbg_task = $service_pbg_task;
|
||||
$this->service_tab_pbg_task = $serviceTabPbgTask;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
dispatch(new ScrapingDataJob());
|
||||
|
||||
$this->info("Scraping job dispatched successfully");
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// public function handle()
|
||||
// {
|
||||
|
||||
try {
|
||||
// Create a record with "processing" status
|
||||
$import_datasource = ImportDatasource::create([
|
||||
'message' => 'Initiating scraping...',
|
||||
'response_body' => null,
|
||||
'status' => 'processing'
|
||||
]);
|
||||
// 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 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 ServicePbgTask with injected Guzzle Client
|
||||
// $this->service_pbg_task->run_service();
|
||||
|
||||
// run the service pbg task assignments
|
||||
$this->service_tab_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.'
|
||||
]);
|
||||
// // Update the record status to "success" after completion
|
||||
// $import_datasource->update([
|
||||
// 'status' => 'success',
|
||||
// 'message' => 'Scraping completed successfully.',
|
||||
// 'finish_time' => now()
|
||||
// ]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// } 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()
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// 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()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user