Skip to content

Commit

Permalink
Controllers: Introduce versioning controller
Browse files Browse the repository at this point in the history
- Introduce controller to fetch and validate latest version on git and version that send and exist on client version. If version are not match, then return error to notify user clear cache their browser manually
  • Loading branch information
Nicklas373 committed May 20, 2024
1 parent 4130641 commit 7b51d55
Show file tree
Hide file tree
Showing 4 changed files with 622 additions and 0 deletions.
136 changes: 136 additions & 0 deletions app/Helpers/NotificationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,140 @@ function sendDailyTaskNotify($compTotalScs, $compTotalErr, $cnvTotalScs, $cnvTot
}
}
}

function sendErrGlobalNotify($processEndpoint, $processName, $processId , $status, $errReason, $errCode) {
$CurrentTime = AppHelper::instance()->getCurrentTimeZone();
$message = "<b>HANA API Alert</b>
\nStatus: <b>".$status."</b>".
"\nStart At: <b>".$CurrentTime.
"</b>\nEnvironment: <b>".env('APP_ENV').
"\n\n</b>Services: <b>Backend Services</b>".
"\nSource: <b>https://gw.hana-ci.com</b>".
"\nEndpoint: <b>".$processEndpoint.
"</b>\n\nProcess: <b>".$processName.
"</b>\nProcess Id: <b>".$processId.
"</b>\nType: <b>Universal Notifyr</b>".
"\n\nError Reason: <b>".$errReason.
"</b>\nError Log: <pre><code>".$errCode.
"</code></pre>";
try {
$response = Telegram::sendMessage([
'chat_id' => env('TELEGRAM_CHAT_ID'),
'text' => $message,
'parse_mode' => 'HTML'
]);
$messageId = $response->getMessageId();

try {
DB::table('notifyLogs')->insert([
'processId' => $processId,
'notifyName' => 'Telegram SDK',
'notifyResult' => true,
'notifyMessage' => 'Message has been sent !',
'notifyResponse' => $response
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $ex->getMessage());
}
} catch (\Telegram\Bot\Exceptions\TelegramResponseException $e) {
try {
if ($e->getHttpStatusCode() == null) {
$httpStatus = null;
} else {
$httpStatus = $e->getHttpStatusCode();
}
DB::table('notifyLogs')->insert([
'processId' => $processId,
'notifyName' => 'Telegram SDK',
'notifyResult' => false,
'notifyMessage' => 'TelegramResponseException',
'notifyResponse' => $e->getMessage()+' | '+$httpStatus+' | '+$e->getErrorType()
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $ex->getMessage());
}
} catch (\Exception $e) {
try {
DB::table('notifyLogs')->insert([
'processId' => $processId,
'notifyName' => 'Telegram SDK',
'notifyResult' => false,
'notifyMessage' => 'Unexpected handling exception !',
'notifyResponse' => $e->getMessage()
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $ex->getMessage());
}
}
}

function sendVersioningErrNotify($versioningFE, $versioningGitFE, $versioningBE , $versioningGitBE, $status, $processId, $errReason, $errCode) {
$CurrentTime = AppHelper::instance()->getCurrentTimeZone();
$message = "<b>HANA API Alert</b>
\nStatus: <b>".$status."</b>".
"\nStart At: <b>".$CurrentTime.
"</b>\nEnvironment: <b>".env('APP_ENV').
"\n\n</b>Services: <b>Backend Services</b>".
"\nSource: <b>https://gw.hana-ci.com</b>".
"\nEndpoint: <b>api/v1/version</b>".
"\n\nProcess: <b>Versioning".
"</b>\nProcess Id: <b>".$processId.
"</b>\nType: <b>Versioning Check</b>".
"\n\nBE Version: <b>".$versioningBE.
"</b>\nBE Version GIT: <b>".$versioningGitBE.
"</b>\nFE Version: <b>".$versioningFE.
"</b>\nFE Version GIT: <b>".$versioningGitFE.
"\n\n</b>Error Reason: <b>".$errReason.
"</b>\nError Log: <pre><code>".$errCode.
"</code></pre>";
try {
$response = Telegram::sendMessage([
'chat_id' => env('TELEGRAM_CHAT_ID'),
'text' => $message,
'parse_mode' => 'HTML'
]);
$messageId = $response->getMessageId();

try {
DB::table('notifyLogs')->insert([
'processId' => $processId,
'notifyName' => 'Telegram SDK',
'notifyResult' => true,
'notifyMessage' => 'Message has been sent !',
'notifyResponse' => $response
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $ex->getMessage());
}
} catch (\Telegram\Bot\Exceptions\TelegramResponseException $e) {
try {
if ($e->getHttpStatusCode() == null) {
$httpStatus = null;
} else {
$httpStatus = $e->getHttpStatusCode();
}
DB::table('notifyLogs')->insert([
'processId' => $processId,
'notifyName' => 'Telegram SDK',
'notifyResult' => false,
'notifyMessage' => 'TelegramResponseException',
'notifyResponse' => $e->getMessage()+' | '+$httpStatus+' | '+$e->getErrorType()
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $ex->getMessage());
}
} catch (\Exception $e) {
try {
DB::table('notifyLogs')->insert([
'processId' => $processId,
'notifyName' => 'Telegram SDK',
'notifyResult' => false,
'notifyMessage' => 'Unexpected handling exception !',
'notifyResponse' => $e->getMessage()
]);
} catch (QueryException $ex) {
Log::error('Query Exception failed with: '. $ex->getMessage());
}
}
}
}
Loading

0 comments on commit 7b51d55

Please sign in to comment.