fix syncronize using worker and add duration syncronize
This commit is contained in:
@@ -344,22 +344,44 @@ class ServiceTabPbgTask
|
||||
|
||||
private function refreshToken()
|
||||
{
|
||||
try {
|
||||
$newAuthToken = $this->service_token->refresh_token($this->user_refresh_token);
|
||||
|
||||
if (!isset($newAuthToken['access']) || !isset($newAuthToken['refresh'])) {
|
||||
throw new \Exception("Invalid refresh token response.");
|
||||
}
|
||||
|
||||
$this->user_token = $newAuthToken['access'];
|
||||
$this->user_refresh_token = $newAuthToken['refresh'];
|
||||
|
||||
Log::info("Token refreshed successfully.");
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Token refresh failed: " . $e->getMessage());
|
||||
Log::info("Attempting to log in again...");
|
||||
$maxRetries = 3; // Maximum retry attempts
|
||||
$attempt = 0;
|
||||
|
||||
while ($attempt < $maxRetries) {
|
||||
try {
|
||||
$attempt++;
|
||||
Log::info("Attempt $attempt: Refreshing token...");
|
||||
|
||||
$newAuthToken = $this->service_token->refresh_token($this->user_refresh_token);
|
||||
|
||||
if (!isset($newAuthToken['access']) || !isset($newAuthToken['refresh'])) {
|
||||
throw new \Exception("Invalid refresh token response.");
|
||||
}
|
||||
|
||||
$this->user_token = $newAuthToken['access'];
|
||||
$this->user_refresh_token = $newAuthToken['refresh'];
|
||||
|
||||
Log::info("Token refreshed successfully on attempt $attempt.");
|
||||
return; // Exit function on success
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Token refresh failed on attempt $attempt: " . $e->getMessage());
|
||||
|
||||
if ($attempt >= $maxRetries) {
|
||||
Log::info("Max retries reached. Attempting to log in again...");
|
||||
break;
|
||||
}
|
||||
|
||||
sleep(30); // Wait for 30 seconds before retrying
|
||||
}
|
||||
}
|
||||
|
||||
// If refresh fails after retries, attempt re-login
|
||||
$attempt = 0;
|
||||
while ($attempt < $maxRetries) {
|
||||
try {
|
||||
$attempt++;
|
||||
Log::info("Attempt $attempt: Re-logging in...");
|
||||
|
||||
$loginAgain = $this->service_token->get_token(); // Login again
|
||||
|
||||
if (!isset($loginAgain['access']) || !isset($loginAgain['refresh'])) {
|
||||
@@ -369,11 +391,18 @@ class ServiceTabPbgTask
|
||||
$this->user_token = $loginAgain['access'];
|
||||
$this->user_refresh_token = $loginAgain['refresh'];
|
||||
|
||||
Log::info("Re-login successful.");
|
||||
Log::info("Re-login successful on attempt $attempt.");
|
||||
return; // Exit function on success
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Re-login failed: " . $e->getMessage());
|
||||
throw new \Exception("Both token refresh and login failed.". $e->getMessage());
|
||||
Log::error("Re-login failed on attempt $attempt: " . $e->getMessage());
|
||||
|
||||
if ($attempt >= $maxRetries) {
|
||||
throw new \Exception("Both token refresh and login failed after $maxRetries attempts. " . $e->getMessage());
|
||||
}
|
||||
|
||||
sleep(30); // Wait for 30 seconds before retrying
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user