change column type expertise and fix syncronize simbg service
This commit is contained in:
@@ -34,7 +34,7 @@ class ExecuteScraping extends Command
|
||||
}
|
||||
public function handle()
|
||||
{
|
||||
SyncronizeSIMBG::dispatch();
|
||||
SyncronizeSIMBG::dispatch()->onQueue('default');
|
||||
Log::info("running scheduler daily scraping");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,14 @@ class SyncronizeSIMBG implements ShouldQueue
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
try {
|
||||
$serviceSIMBG = app(ServiceSIMBG::class);
|
||||
$serviceSIMBG->syncTaskPBG();
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("SyncronizeSIMBG Job Failed: " . $e->getMessage(), [
|
||||
'exception' => $e,
|
||||
]);
|
||||
$this->fail($e); // Mark the job as failed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class TaskAssignment extends Model
|
||||
protected $fillable = [
|
||||
'user_id', 'name', 'username', 'email', 'phone_number', 'role',
|
||||
'role_name', 'is_active', 'file', 'expertise', 'experience',
|
||||
'is_verif', 'uid', 'status', 'status_name', 'note', 'pbg_task_uid'
|
||||
'is_verif', 'uid', 'status', 'status_name', 'note', 'pbg_task_uid', 'tas_id'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
||||
@@ -339,20 +339,12 @@ class ServiceSIMBG
|
||||
$decodedResponse = json_decode($response->getContent(), true);
|
||||
|
||||
if (isset($decodedResponse['errors']['code']) && $decodedResponse['errors']['code'] === 'token_not_valid') {
|
||||
Log::warning("Token is invalid, refreshing token...");
|
||||
|
||||
// Regenerate token
|
||||
$initResToken = $this->getToken();
|
||||
|
||||
// Check if new token is valid
|
||||
if (!empty($initResToken->original['data']['token']['access'])) {
|
||||
$new_token = $initResToken->original['data']['token']['access'];
|
||||
|
||||
// **Fix: Update headers before retrying**
|
||||
$headers['Authorization'] = "Bearer " . $new_token;
|
||||
|
||||
Log::info("Token refreshed successfully, retrying API request...");
|
||||
continue; // Retry with new token
|
||||
continue;
|
||||
} else {
|
||||
Log::error("Failed to refresh token");
|
||||
return $this->resError("Failed to refresh token");
|
||||
@@ -464,29 +456,21 @@ class ServiceSIMBG
|
||||
'Authorization' => "Bearer " . $token,
|
||||
];
|
||||
|
||||
for ($attempt = 0; $attempt < 2; $attempt++) { // Try twice (original + retry)
|
||||
for ($attempt = 0; $attempt < 2; $attempt++) {
|
||||
$res = $this->service_client->get($url, $headers);
|
||||
|
||||
// Check if response is JsonResponse and decode it
|
||||
if ($res instanceof \Illuminate\Http\JsonResponse) {
|
||||
$decodedResponse = json_decode($res->getContent(), true);
|
||||
|
||||
// Handle invalid token case
|
||||
if (isset($decodedResponse['errors']['code']) && $decodedResponse['errors']['code'] === 'token_not_valid') {
|
||||
Log::warning("Token is invalid, refreshing token...");
|
||||
|
||||
// Regenerate the token
|
||||
$initResToken = $this->getToken();
|
||||
|
||||
// Check if the new token is valid
|
||||
if (!empty($initResToken->original['data']['token']['access'])) {
|
||||
$new_token = $initResToken->original['data']['token']['access'];
|
||||
|
||||
// **Fix: Update headers with the new token**
|
||||
$headers['Authorization'] = "Bearer " . $new_token;
|
||||
|
||||
Log::info("Token refreshed successfully, retrying API request...");
|
||||
continue; // Retry the request with the new token
|
||||
continue;
|
||||
} else {
|
||||
Log::error("Failed to refresh token");
|
||||
return $this->resError("Failed to refresh token");
|
||||
@@ -494,7 +478,6 @@ class ServiceSIMBG
|
||||
}
|
||||
}
|
||||
|
||||
// If request succeeds, break out of retry loop
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -502,7 +485,6 @@ class ServiceSIMBG
|
||||
$responseData = $res->original ?? [];
|
||||
$data = $responseData['data']['data'] ?? [];
|
||||
if (empty($data)) {
|
||||
Log::error("API response indicates failure", ['url' => $url, 'uuid' => $uuid, 'response' => $responseData]);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -583,7 +565,7 @@ class ServiceSIMBG
|
||||
|
||||
foreach ($datas as $data) {
|
||||
$task_assignments[] = [
|
||||
'pbg_task_uid' => $uuid, // Assuming this is a foreign key
|
||||
'pbg_task_uid' => $uuid,
|
||||
'user_id' => $data['user_id'],
|
||||
'name' => $data['name'],
|
||||
'username' => $data['username'],
|
||||
@@ -592,22 +574,23 @@ class ServiceSIMBG
|
||||
'role' => $data['role'],
|
||||
'role_name' => $data['role_name'],
|
||||
'is_active' => $data['is_active'],
|
||||
'file' => json_encode($data['file']), // Store as JSON if it's an array
|
||||
'expertise' => $data['expertise'],
|
||||
'experience' => $data['experience'],
|
||||
'file' => !empty($data['file']) ? json_encode($data['file']) : null,
|
||||
'expertise' => !empty($data['expertise']) ? json_encode($data['expertise']) : null,
|
||||
'experience' => !empty($data['experience']) ? json_encode($data['experience']) : null,
|
||||
'is_verif' => $data['is_verif'],
|
||||
'uid' => $data['uid'], // Unique identifier
|
||||
'uid' => $data['uid'],
|
||||
'status' => $data['status'],
|
||||
'status_name' => $data['status_name'],
|
||||
'note' => $data['note'],
|
||||
'ta_id' => $data['id'],
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
TaskAssignment::upsert(
|
||||
$task_assignments, // Data to insert/update
|
||||
['uid'], // Unique key for conflict resolution
|
||||
['name', 'username', 'email', 'phone_number', 'role', 'role_name', 'is_active', 'file', 'expertise', 'experience', 'is_verif', 'status', 'status_name', 'note', 'updated_at']
|
||||
$task_assignments,
|
||||
['uid'],
|
||||
['ta_id','name', 'username', 'email', 'phone_number', 'role', 'role_name', 'is_active', 'file', 'expertise', 'experience', 'is_verif', 'status', 'status_name', 'note', 'updated_at']
|
||||
);
|
||||
return true;
|
||||
}catch(Exception $e){
|
||||
|
||||
@@ -79,6 +79,8 @@ return [
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||
PDO::ATTR_TIMEOUT => 40000,
|
||||
PDO::MYSQL_ATTR_INIT_COMMAND => "SET SESSION wait_timeout=40000; SET SESSION interactive_timeout=40000;"
|
||||
]) : [],
|
||||
],
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ return [
|
||||
// set timeout queue
|
||||
|
||||
'worker' => [
|
||||
'timeout' => 300
|
||||
'timeout' => 40000
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('task_assignments', function (Blueprint $table) {
|
||||
$table->json('expertise')->nullable()->change();
|
||||
$table->json('experience')->nullable()->change();
|
||||
$table->bigInteger('ta_id')->nullable()->after('id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('task_assignments', function (Blueprint $table) {
|
||||
$table->text('expertise')->nullable()->change();
|
||||
$table->text('experience')->nullable()->change();
|
||||
$table->dropColumn('ta_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user