add table scraping log and datatable server side
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\Enums\ImportDatasourceStatus;
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Models\ImportDatasource;
|
||||
use App\Models\PbgTaskIndexIntegrations;
|
||||
use App\Models\PbgTaskPrasarana;
|
||||
use App\Models\PbgTaskRetributions;
|
||||
@@ -31,6 +33,7 @@ class ServiceSIMBG
|
||||
|
||||
$res = $clientHelper->post($url, $body);
|
||||
if(!$res->original['success']){
|
||||
\Log::error("Token not retrieved ", ['response' => $res]);
|
||||
return null;
|
||||
}
|
||||
return $res;
|
||||
@@ -90,8 +93,17 @@ class ServiceSIMBG
|
||||
$clientHelper = new ServiceClient($_ENV['SIMBG_HOST']);
|
||||
$resToken = $this->getToken();
|
||||
|
||||
// create log import datasource
|
||||
$importDatasource = ImportDatasource::create([
|
||||
'status' => ImportDatasourceStatus::Processing->value,
|
||||
]);
|
||||
|
||||
if (!isset($resToken) || empty($resToken->original['data']['token']['access'])) {
|
||||
\Log::error("Token not retrieved for syncTaskList");
|
||||
$importDatasource->update([
|
||||
'status' => ImportDatasourceStatus::Failed->value,
|
||||
'message' => 'Failed to retrive token'
|
||||
]);
|
||||
return ApiResponse::errorResponse("Failed to retrieve token", 401);
|
||||
}
|
||||
|
||||
@@ -109,6 +121,10 @@ class ServiceSIMBG
|
||||
$initialResponse = $clientHelper->get($url, $headers);
|
||||
if (empty($initialResponse->original['data']['total_page'])) {
|
||||
\Log::error("Invalid response: no total_page", ['response' => $initialResponse->original]);
|
||||
$importDatasource->update([
|
||||
'status' => ImportDatasourceStatus::Failed->value,
|
||||
'message' => 'Invalid response: no total_page'
|
||||
]);
|
||||
return ApiResponse::errorResponse("Invalid response from API", 400);
|
||||
}
|
||||
|
||||
@@ -129,7 +145,10 @@ class ServiceSIMBG
|
||||
|
||||
if (empty($response->original['data']['data'])) {
|
||||
\Log::warning("No data found on page", ['page' => $currentPage]);
|
||||
continue;
|
||||
$importDatasource->update([
|
||||
'status' => ImportDatasourceStatus::Success->value,
|
||||
'message' => 'Success but no data loaded on page'
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($response->original['data']['data'] as $item) {
|
||||
@@ -171,6 +190,11 @@ class ServiceSIMBG
|
||||
'error' => $e->getMessage(),
|
||||
'task' => $item,
|
||||
]);
|
||||
$importDatasource->update([
|
||||
'status' => ImportDatasourceStatus::Failed->value,
|
||||
'message' => $e->getMessage(),
|
||||
'response_body' => $item
|
||||
]);
|
||||
$failedCount++;
|
||||
}
|
||||
}
|
||||
@@ -181,8 +205,13 @@ class ServiceSIMBG
|
||||
"failedCount" => $failedCount,
|
||||
];
|
||||
|
||||
|
||||
$importDatasource->update([
|
||||
'status' => ImportDatasourceStatus::Success->value,
|
||||
'message' => "Successfully success data: " .$savedCount. " failed data : " .$failedCount
|
||||
]);
|
||||
|
||||
\Log::info("syncTaskList completed", $result);
|
||||
|
||||
return ApiResponse::successResponse(json_encode($result), "Successfully saved");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user