Skip to content

Commit

Permalink
v3.3.8 20241107 [Frontend Module] (#275)
Browse files Browse the repository at this point in the history
**Recent changelog:**
- [Exceptions: Fix may duplicate logic for create
models](579a079)
- [Resources: kao-logic: Fix wrong BE endpoint
route](734044d)
- [Console: Kernel: Fix may-duplicate primary
ID](dc5a1c5)
- [Helpers: Properly use Laravel Eloquent
models](41af657)
- [Resources: kao-logic: Simplify XHR request
method](56b69ed)
  • Loading branch information
Nicklas373 authored Nov 7, 2024
2 parents 335c9b2 + 3d42e2a commit e610de8
Show file tree
Hide file tree
Showing 10 changed files with 662 additions and 667 deletions.
88 changes: 47 additions & 41 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule): void
{
// Generate unique UUID
$uuid = AppHelper::Instance()->generateUniqueUuid(jobLogModel::class, 'processId');
$muuid = AppHelper::Instance()->generateSingleUniqueUuid(jobLogModel::class, 'groupId');
$cacheClearUUIDProc = AppHelper::Instance()->generateUniqueUuid(jobLogModel::class, 'processId');
$cacheClearUUIDGroup = AppHelper::Instance()->generateUniqueUuid(jobLogModel::class, 'groupId');
$optimizeClearUUIDProc = AppHelper::Instance()->generateUniqueUuid(jobLogModel::class, 'processId');
$optimizeClearUUIDGroup = AppHelper::Instance()->generateUniqueUuid(jobLogModel::class, 'groupId');
$viewClearUUIDProc = AppHelper::Instance()->generateUniqueUuid(jobLogModel::class, 'processId');
$viewClearUUIDGroup = AppHelper::Instance()->generateUniqueUuid(jobLogModel::class, 'groupId');
$viewCacheUUIDProc = AppHelper::Instance()->generateUniqueUuid(jobLogModel::class, 'processId');
$viewCacheUUIDGroup = AppHelper::Instance()->generateUniqueUuid(jobLogModel::class, 'groupId');

// Carbon timezone
date_default_timezone_set('Asia/Jakarta');
Expand All @@ -33,10 +39,10 @@ protected function schedule(Schedule $schedule): void
->weekly()
->environments(env('APP_ENV'))
->timezone('Asia/Jakarta')
->before(function(AppHelper $helper) use($uuid, $muuid, $startProc) {
->before(function(AppHelper $helper) use($cacheClearUUIDProc, $cacheClearUUIDGroup, $startProc) {
appLogModel::create([
'processId' => $uuid,
'groupId' => $muuid,
'processId' => $cacheClearUUIDProc,
'groupId' => $cacheClearUUIDGroup,
'errReason' => null,
'errStatus' => null
]);
Expand All @@ -46,28 +52,28 @@ protected function schedule(Schedule $schedule): void
'jobsRuntime' => 'weekly',
'jobsResult' => false,
'groupId' => $muuid,
'processId' => $uuid,
'processId' => $cacheClearUUIDProc,
'procStartAt' => $startProc
]);
})
->after(function(AppHelper $helper, Stringable $output) use($uuid, $muuid, $startProc) {
->after(function(AppHelper $helper, Stringable $output) use($cacheClearUUIDProc, $cacheClearUUIDGroup, $startProc) {
$start = Carbon::parse($startProc);
$end = Carbon::parse($helper::instance()->getCurrentTimeZone());
$duration = $end->diff($start);
if ($output == null || $output == '' || empty($output) || str_contains($output, 'successfully')) {
jobLogModel::where('processId', '=', $uuid)
jobLogModel::where('processId', '=', $cacheClearUUIDProc)
->update([
'jobsResult' => true,
'procEndAt' => AppHelper::instance()->getCurrentTimeZone(),
'procDuration' => $duration->s.' seconds'
]);
} else {
appLogModel::where('processId', '=', $uuid)
appLogModel::where('processId', '=', $cacheClearUUIDProc)
->update([
'errReason' => 'Laravel Scheduler Error !',
'errStatus' => $output
]);
jobLogModel::where('processId', '=', $uuid)
jobLogModel::where('processId', '=', $cacheClearUUIDProc)
->update([
'jobsResult' => false,
'procEndAt' => AppHelper::instance()->getCurrentTimeZone(),
Expand All @@ -76,7 +82,7 @@ protected function schedule(Schedule $schedule): void
NotificationHelper::Instance()->sendSchedErrNotify(
'cache:clear',
'weekly',
$muuid,
$cacheClearUUIDGroup,
'FAIL',
'Laravel Scheduler Error !',
$output
Expand All @@ -88,10 +94,10 @@ protected function schedule(Schedule $schedule): void
->weekly()
->environments(env('APP_ENV'))
->timezone('Asia/Jakarta')
->before(function(AppHelper $helper) use($uuid, $muuid, $startProc) {
->before(function(AppHelper $helper) use($optimizeClearUUIDProc, $optimizeClearUUIDGroup, $startProc) {
appLogModel::create([
'processId' => $uuid,
'groupId' => $muuid,
'processId' => $optimizeClearUUIDProc,
'groupId' => $optimizeClearUUIDGroup,
'errReason' => null,
'errStatus' => null
]);
Expand All @@ -100,29 +106,29 @@ protected function schedule(Schedule $schedule): void
'jobsEnv' => env('APP_ENV'),
'jobsRuntime' => 'weekly',
'jobsResult' => false,
'groupId' => $muuid,
'processId' => $uuid,
'groupId' => $optimizeClearUUIDGroup,
'processId' => $optimizeClearUUIDProc,
'procStartAt' => $startProc
]);
})
->after(function(AppHelper $helper, Stringable $output) use($uuid, $muuid, $startProc) {
->after(function(AppHelper $helper, Stringable $output) use($optimizeClearUUIDProc, $optimizeClearUUIDGroup, $startProc) {
$start = Carbon::parse($startProc);
$end = Carbon::parse($helper::instance()->getCurrentTimeZone());
$duration = $end->diff($start);
if ($output == null || $output == '' || empty($output) || str_contains($output, 'DONE')) {
jobLogModel::where('processId', '=', $uuid)
jobLogModel::where('processId', '=', $optimizeClearUUIDProc)
->update([
'jobsResult' => true,
'procEndAt' => AppHelper::instance()->getCurrentTimeZone(),
'procDuration' => $duration->s.' seconds'
]);
} else {
appLogModel::where('processId', '=', $uuid)
appLogModel::where('processId', '=', $optimizeClearUUIDProc)
->update([
'errReason' => 'Laravel Scheduler Error !',
'errStatus' => $output
]);
jobLogModel::where('processId', '=', $uuid)
jobLogModel::where('processId', '=', $optimizeClearUUIDProc)
->update([
'jobsResult' => false,
'procEndAt' => AppHelper::instance()->getCurrentTimeZone(),
Expand All @@ -131,7 +137,7 @@ protected function schedule(Schedule $schedule): void
NotificationHelper::Instance()->sendSchedErrNotify(
'optimize:clear',
'weekly',
$muuid,
$optimizeClearUUIDGroup,
'FAIL',
'Laravel Scheduler Error !',
$output
Expand All @@ -143,10 +149,10 @@ protected function schedule(Schedule $schedule): void
->weekly()
->environments(env('APP_ENV'))
->timezone('Asia/Jakarta')
->before(function(AppHelper $helper) use($uuid, $muuid, $startProc) {
->before(function(AppHelper $helper) use($viewClearUUIDProc, $viewClearUUIDGroup, $startProc) {
appLogModel::create([
'processId' => $uuid,
'groupId' => $muuid,
'processId' => $viewClearUUIDProc,
'groupId' => $viewClearUUIDGroup,
'errReason' => null,
'errStatus' => null
]);
Expand All @@ -155,29 +161,29 @@ protected function schedule(Schedule $schedule): void
'jobsEnv' => env('APP_ENV'),
'jobsRuntime' => 'weekly',
'jobsResult' => false,
'groupId' => $muuid,
'processId' => $uuid,
'groupId' => $viewClearUUIDGroup,
'processId' => $viewClearUUIDProc,
'procStartAt' => $startProc
]);
})
->after(function(AppHelper $helper, Stringable $output) use($uuid, $muuid, $startProc) {
->after(function(AppHelper $helper, Stringable $output) use($viewClearUUIDProc, $viewClearUUIDGroup, $startProc) {
$start = Carbon::parse($startProc);
$end = Carbon::parse($helper::instance()->getCurrentTimeZone());
$duration = $end->diff($start);
if ($output == null || $output == '' || empty($output) || str_contains($output, 'successfully')) {
jobLogModel::where('processId', '=', $uuid)
jobLogModel::where('processId', '=', $viewClearUUIDProc)
->update([
'jobsResult' => true,
'procEndAt' => AppHelper::instance()->getCurrentTimeZone(),
'procDuration' => $duration->s.' seconds'
]);
} else {
appLogModel::where('processId', '=', $uuid)
appLogModel::where('processId', '=', $viewClearUUIDProc)
->update([
'errReason' => 'Laravel Scheduler Error !',
'errStatus' => $output,
]);
jobLogModel::where('processId', '=', $uuid)
jobLogModel::where('processId', '=', $viewClearUUIDProc)
->update([
'jobsResult' => false,
'procEndAt' => AppHelper::instance()->getCurrentTimeZone(),
Expand All @@ -186,7 +192,7 @@ protected function schedule(Schedule $schedule): void
NotificationHelper::Instance()->sendSchedErrNotify(
'view:clear',
'weekly',
$muuid,
$viewClearUUIDGroup,
'FAIL',
'Laravel Scheduler Error !',
$output
Expand All @@ -198,10 +204,10 @@ protected function schedule(Schedule $schedule): void
->weekly()
->environments(env('APP_ENV'))
->timezone('Asia/Jakarta')
->before(function(AppHelper $helper) use($uuid, $muuid, $startProc) {
->before(function(AppHelper $helper) use($viewCacheUUIDProc, $viewCacheUUIDGroup, $startProc) {
appLogModel::create([
'processId' => $uuid,
'groupId' => $muuid,
'processId' => $viewCacheUUIDProc,
'groupId' => $viewCacheUUIDGroup,
'errReason' => null,
'errStatus' => null
]);
Expand All @@ -210,29 +216,29 @@ protected function schedule(Schedule $schedule): void
'jobsEnv' => env('APP_ENV'),
'jobsRuntime' => 'weekly',
'jobsResult' => false,
'groupId' => $muuid,
'processId' => $uuid,
'groupId' => $viewCacheUUIDGroup,
'processId' => $viewCacheUUIDProc,
'procStartAt' => $startProc
]);
})
->after(function(AppHelper $helper, Stringable $output) use($uuid, $muuid, $startProc) {
->after(function(AppHelper $helper, Stringable $output) use($viewCacheUUIDProc, $viewCacheUUIDGroup, $startProc) {
$start = Carbon::parse($startProc);
$end = Carbon::parse($helper::instance()->getCurrentTimeZone());
$duration = $end->diff($start);
if ($output == null || $output == '' || empty($output) || str_contains($output, 'successfully')) {
jobLogModel::where('processId', '=', $uuid)
jobLogModel::where('processId', '=', $viewCacheUUIDProc)
->update([
'jobsResult' => true,
'procEndAt' => AppHelper::instance()->getCurrentTimeZone(),
'procDuration' => $duration->s.' seconds'
]);
} else {
appLogModel::where('processId', '=', $uuid)
appLogModel::where('processId', '=', $viewCacheUUIDProc)
->update([
'errReason' => 'Laravel Scheduler Error !',
'errStatus' => $output,
]);
jobLogModel::where('processId', '=', $uuid)
jobLogModel::where('processId', '=', $viewCacheUUIDProc)
->update([
'jobsResult' => false,
'procEndAt' => AppHelper::instance()->getCurrentTimeZone(),
Expand All @@ -241,7 +247,7 @@ protected function schedule(Schedule $schedule): void
NotificationHelper::Instance()->sendSchedErrNotify(
'view:cache',
'weekly',
$muuid,
$viewCacheUUIDGroup,
'FAIL',
'Laravel Scheduler Error !',
$output
Expand Down
49 changes: 32 additions & 17 deletions app/Helpers/NotificationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static function instance()

function sendRouteErrNotify($processId, $status, $errReason, $errCode) {
$CurrentTime = AppHelper::instance()->getCurrentTimeZone();
$uuid = AppHelper::Instance()->generateUniqueUuid(notifyLogModel::class, 'processId');
$message = "<b>HANA API Alert</b>
\nStatus: <b>".$status."</b>".
"\nStart At: <b>".$CurrentTime.
Expand All @@ -34,8 +35,14 @@ function sendRouteErrNotify($processId, $status, $errReason, $errCode) {
'parse_mode' => 'HTML'
]);
$messageId = $response->getMessageId();
appLogModel::create([
'processId' => $uuid,
'groupId' => $processId,
'errReason' => null,
'errStatus' => null
]);
notifyLogModel::create([
'processId' => $processId,
'processId' => $uuid,
'notifyName' => 'Telegram SDK',
'notifyResult' => true,
'notifyMessage' => 'Message has been sent !',
Expand All @@ -44,24 +51,32 @@ function sendRouteErrNotify($processId, $status, $errReason, $errCode) {
} catch (\Telegram\Bot\Exceptions\TelegramResponseException $e) {
if ($e->getHttpStatusCode() == null) {
$httpStatus = null;
} else {
} else {
$httpStatus = $e->getHttpStatusCode();
}
notifyLogModel::create([
'processId' => $processId,
'notifyName' => 'Telegram SDK',
'notifyResult' => false,
'notifyMessage' => 'TelegramResponseException',
'notifyResponse' => $e->getMessage().' | '.$httpStatus.' | '.$e->getErrorType()
]);
}
appLogModel::where('processId', '=', $uuid)
->update([
'errReason' => 'TelegramResponseException',
'errStatus' => $errReason
]);
notifyLogModel::where('processId', '=', $uuid)
->update([
'notifyResult' => false,
'notifyMessage' => 'TelegramResponseException',
'notifyResponse' => $e->getMessage().' | '.$httpStatus.' | '.$e->getErrorType()
]);
} catch (\Exception $e) {
notifyLogModel::create([
'processId' => $processId,
'notifyName' => 'Telegram SDK',
'notifyResult' => false,
'notifyMessage' => 'Unexpected handling exception !',
'notifyResponse' => $e->getMessage()
]);
appLogModel::where('processId', '=', $uuid)
->update([
'errReason' => 'TelegramResponseException',
'errStatus' => $errReason
]);
notifyLogModel::where('processId', '=', $uuid)
->update([
'notifyResult' => false,
'notifyMessage' => 'Unexpected handling exception !',
'notifyResponse' => $e->getMessage()
]);
}
}
}
Loading

0 comments on commit e610de8

Please sign in to comment.