diff --git a/app/Console/Commands/ExportDatabaseToBI.php b/app/Console/Commands/ExportDatabaseToBI.php index 6081d87a..dfa91a27 100644 --- a/app/Console/Commands/ExportDatabaseToBI.php +++ b/app/Console/Commands/ExportDatabaseToBI.php @@ -38,6 +38,7 @@ class ExportDatabaseToBI extends Command ]; + protected $task; protected $success; protected $failure; protected $message; @@ -117,69 +118,93 @@ private function sendTableDataToDataWarehouse($table_name, $delta_field, $hidden ]); $this->task = $task; + + try { - // Get the latest success job - $last_job = ScheduleJobAudit::where('job_name', $job_name) - ->where('status','Completed') - ->orderBy('end_time', 'desc')->first(); + // Get the latest success job + $last_job = ScheduleJobAudit::where('job_name', $job_name) + ->where('status','Completed') + ->orderBy('end_time', 'desc')->first(); - $last_start_time = $last_job ? $last_job->start_time : '2000-01-01' ; + $last_start_time = $last_job ? $last_job->start_time : '2000-01-01' ; - $this->LogMessage("Table '{$table_name}' Detail to BI (Datawarehouse) start on " . now() ); - $this->Logmessage(""); - $this->Logmessage("Table Name : '{$table_name}' "); - $this->LogMessage("The Last send completed time : " . $last_start_time); - $this->LogMessage("The schedule Job id : " . $task->id); - $this->LogMessage("The command name : " . $job_name); - - // Main Process for each table - $sql = DB::table($table_name) - ->when( $last_job && $delta_field, function($q) use($last_start_time, $delta_field, $hidden_fields ) { - return $q->where($delta_field, '>=', $last_start_time); - }) - ->orderBy('id'); + $this->LogMessage("Table '{$table_name}' Detail to BI (Datawarehouse) start on " . now() ); + $this->Logmessage(""); + $this->Logmessage("Table Name : '{$table_name}' "); + $this->LogMessage("The Last send completed time : " . $last_start_time); + $this->LogMessage("The schedule Job id : " . $task->id); + $this->LogMessage("The command name : " . $job_name); - // Chucking - $row_count = 0; - $sql->chunk(5000, function($chuck) use($task, $table_name, $hidden_fields, $last_job, &$row_count, &$n) { - $this->LogMessage( "Sending table '{$table_name}' batch (5000) - " . ++$n ); - - //$chuck->makeHidden(['password', 'remember_token']); - if ($hidden_fields) { - foreach($chuck as $item) { - foreach($hidden_fields as $hidden_field) { - // unset($item->password); - unset($item->$hidden_field); - } + // Main Process for each table + $sql = DB::table($table_name) + ->when( $last_job && $delta_field, function($q) use($last_start_time, $delta_field, $hidden_fields ) { + return $q->where($delta_field, '>=', $last_start_time); + }) + ->orderBy('id'); + + // Chucking + $row_count = 0; + $sql->chunk(5000, function($chuck) use($task, $table_name, $hidden_fields, $last_job, &$row_count, &$n) { + $this->LogMessage( "Sending table '{$table_name}' batch (5000) - " . ++$n ); + + //$chuck->makeHidden(['password', 'remember_token']); + if ($hidden_fields) { + foreach($chuck as $item) { + foreach($hidden_fields as $hidden_field) { + // unset($item->password); + unset($item->$hidden_field); + } + } } - } - $pushdata = new stdClass(); - $pushdata->table_name = $table_name; - $pushdata->table_data = json_encode($chuck); - $pushdata->delta_ind = $last_job ? "1" : "0"; - - $result = $this->sendData( $pushdata ); - if ($result) { - // Log to the table - foreach($chuck as $row) { - ExportAuditLog::create([ - 'schedule_job_name' => $task->job_name, - 'schedule_job_id' => $task->id, - 'to_application' => 'BI', - 'table_name' => $table_name, - 'row_id' => $row->id, - 'row_values' => json_encode($row), - ]); - - $row_count += 1; + $pushdata = new stdClass(); + $pushdata->table_name = $table_name; + $pushdata->table_data = json_encode($chuck); + $pushdata->delta_ind = $last_job ? "1" : "0"; + + $result = $this->sendData( $pushdata ); + if ($result) { + // Log to the table + foreach($chuck as $row) { + ExportAuditLog::create([ + 'schedule_job_name' => $task->job_name, + 'schedule_job_id' => $task->id, + 'to_application' => 'BI', + 'table_name' => $table_name, + 'row_id' => $row->id, + 'row_values' => json_encode($row), + ]); + + $row_count += 1; + } } + + unset($pushdata); + }); + + } catch (\Exception $ex) { + + // log message in system + if ($this->task) { + $this->task->status = 'Error'; + $this->task->end_time = Carbon::now(); + $this->task->message = $this->task->message . PHP_EOL . $ex->getMessage() . PHP_EOL; + $this->task->save(); } - - unset($pushdata); - }); + + // send out email notification + $notify = new \App\MicrosoftGraph\SendEmailNotification(); + $notify->job_id = $this->task ? $this->task->id : null; + $notify->job_name = $job_name; + $notify->error_message = $ex->getMessage(); + $notify->send(); + + // write message to the log + throw new Exception($ex); + + } $this->LogMessage("" ); $this->LogMessage("Success (No of Batch ) - " . $this->success); @@ -202,7 +227,7 @@ private function sendTableDataToDataWarehouse($table_name, $delta_field, $hidden protected function sendData($pushdata) { - try { + // try { $response = Http::withBasicAuth( env('ODS_USERNAME'), @@ -224,14 +249,14 @@ protected function sendData($pushdata) { return false; } - } catch (\Exception $ex) { + // } catch (\Exception $ex) { - // log message in system - $this->status = 'Error'; - $this->LogMessage( $ex->getMessage() ); + // // log message in system + // $this->status = 'Error'; + // $this->LogMessage( $ex->getMessage() ); - throw new Exception($ex); - } + // throw new Exception($ex); + // } } diff --git a/app/Console/Commands/ExportPledgesToPSFT.php b/app/Console/Commands/ExportPledgesToPSFT.php index abe6d448..d3fc8ea3 100644 --- a/app/Console/Commands/ExportPledgesToPSFT.php +++ b/app/Console/Commands/ExportPledgesToPSFT.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use Carbon\Carbon; +use Exception; use App\Models\User; use App\Models\Pledge; use App\Models\PayCalendar; @@ -36,6 +37,7 @@ class ExportPledgesToPSFT extends Command protected $description = 'Sending pledge transactions to PeopleSoft via ODS'; /* Source Type is HCM */ + protected $task; protected $message; protected $status; protected $bypass_rule_for_testing_purpose; @@ -75,40 +77,63 @@ public function handle() $this->bypass_rule_for_testing_purpose = true; } - $this->task = ScheduleJobAudit::Create([ - 'job_name' => $this->signature, - 'start_time' => Carbon::now(), - 'status' => 'Processing', - ]); + try { + $this->task = ScheduleJobAudit::Create([ + 'job_name' => $this->signature, + 'start_time' => Carbon::now(), + 'status' => 'Processing', + ]); - $this->LogMessage("Process run on " . today()->format('Y-m-d')); - if (!(App::environment('prod'))) { - $this->LogMessage("Bypass Rule (when to send to PSFT) for testing purpose is " . ($this->bypass_rule_for_testing_purpose ? 'Yes' : 'No')); - } - $this->LogMessage( "" ); - // Step 1 : Send Campiagn Type data to PeopleSoft access endpoint - $this->LogMessage( now() ); - $this->LogMessage("1) Sending Annual Campaign Type pledge data to PeopleSoft"); - $this->sendCampaignDonationToPeopleSoft(); - - // Step 2 : Send Donate Now Pledge data to PeopleSoft access endpoint - $this->LogMessage( "" ); - $this->LogMessage("2) Sending Donate Now Type pledge data to PeopleSoft"); - $this->sendDonateNowToPeopleSoft(); - - // Step 3 : Send Special Campaign Pledge data to PeopleSoft access endpoint - $this->LogMessage( "" ); - $this->LogMessage("3) Sending Special Campaign Type pledge data to PeopleSoft"); - $this->sendSpecialCampaignToPeopleSoft(); - - // Update the Task Audit log - $this->task->end_time = Carbon::now(); - $this->task->status = $this->status; - $this->task->message = $this->message; - $this->task->save(); + $this->LogMessage("Process run on " . today()->format('Y-m-d')); + if (!(App::environment('prod'))) { + $this->LogMessage("Bypass Rule (when to send to PSFT) for testing purpose is " . ($this->bypass_rule_for_testing_purpose ? 'Yes' : 'No')); + } + $this->LogMessage( "" ); + + // Step 1 : Send Campiagn Type data to PeopleSoft access endpoint + $this->LogMessage( now() ); + $this->LogMessage("1) Sending Annual Campaign Type pledge data to PeopleSoft"); + $this->sendCampaignDonationToPeopleSoft(); + + // Step 2 : Send Donate Now Pledge data to PeopleSoft access endpoint + $this->LogMessage( "" ); + $this->LogMessage("2) Sending Donate Now Type pledge data to PeopleSoft"); + $this->sendDonateNowToPeopleSoft(); + + // Step 3 : Send Special Campaign Pledge data to PeopleSoft access endpoint + $this->LogMessage( "" ); + $this->LogMessage("3) Sending Special Campaign Type pledge data to PeopleSoft"); + $this->sendSpecialCampaignToPeopleSoft(); + + // Update the Task Audit log + $this->task->end_time = Carbon::now(); + $this->task->status = $this->status; + $this->task->message = $this->message; + $this->task->save(); + } catch (\Exception $ex) { + + // log message in system + if ($this->task) { + $this->task->status = 'Error'; + $this->task->end_time = Carbon::now(); + $this->task->message = $ex->getMessage() . PHP_EOL; + $this->task->save(); + } + + // send out email notification + $notify = new \App\MicrosoftGraph\SendEmailNotification(); + $notify->job_id = $this->task ? $this->task->id : null; + $notify->job_name = $this->signature; + $notify->error_message = $ex->getMessage(); + $notify->send(); + + // write message to the log + throw new Exception($ex); + + } } @@ -517,41 +542,27 @@ private function sendSpecialCampaignToPeopleSoft() { protected function sendData($pushdata) { - try { - - $response = Http::withBasicAuth( - env('ODS_USERNAME'), - env('ODS_TOKEN') - )->withBody( json_encode($pushdata), 'application/json') - ->post( env('ODS_OUTBOUND_PLEDGE_PSFT_ENDPOINT') ); - - if ($response->successful()) { - $this->success += 1; - return true; - - } else { - - // log message in system - $this->status = 'Error'; - $this->LogMessage( "(Error) - Data - " . json_encode($pushdata) ); - $this->LogMessage( " - " . $response->status() . ' - ' . $response->body() ); + $response = Http::withBasicAuth( + env('ODS_USERNAME'), + env('ODS_TOKEN') + )->withBody( json_encode($pushdata), 'application/json') + ->post( env('ODS_OUTBOUND_PLEDGE_PSFT_ENDPOINT') ); - $this->failure += 1; + if ($response->successful()) { + $this->success += 1; + return true; - return false; - } - - } catch (\Exception $ex) { + } else { // log message in system $this->status = 'Error'; - $this->LogMessage( "(Error) - " . json_encode($pushdata) ); - $this->LogMessage( " " - $ex->getMessage() ); - - throw new Exception($ex); + $this->LogMessage( "(Error) - Data - " . json_encode($pushdata) ); + $this->LogMessage( " - " . $response->status() . ' - ' . $response->body() ); - } + $this->failure += 1; + return false; + } } diff --git a/app/Console/Commands/ImportCities.php b/app/Console/Commands/ImportCities.php index 8b8cd293..acf4fa57 100644 --- a/app/Console/Commands/ImportCities.php +++ b/app/Console/Commands/ImportCities.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use Carbon\Carbon; +use Exception; use App\Models\EmployeeJob; use App\Models\PledgeHistory; use App\Models\City; @@ -12,6 +13,9 @@ class ImportCities extends Command { + + protected $task; + /** * The name and signature of the console command. * @@ -45,21 +49,45 @@ public function handle() { ini_set('memory_limit', '4096M'); - $task = ScheduleJobAudit::Create([ - 'job_name' => $this->signature, - 'start_time' => Carbon::now(), - 'status','Initiated' - ]); + try { + + $this->task = ScheduleJobAudit::Create([ + 'job_name' => $this->signature, + 'start_time' => Carbon::now(), + 'status','Initiated' + ]); + + $this->info( now() ); + $this->info("Update/Create - City Information"); + $this->UpdateCities(); + $this->info( now() ); + + // Update the Task Audit log + $this->task->end_time = Carbon::now(); + $this->task->status = 'Completed'; + $this->task->save(); + + } catch (\Exception $ex) { + + // log message in system + if ($this->task) { + $this->task->status = 'Error'; + $this->task->end_time = Carbon::now(); + $this->task->message = $ex->getMessage() . PHP_EOL; + $this->task->save(); + } + + // send out email notification + $notify = new \App\MicrosoftGraph\SendEmailNotification(); + $notify->job_id = $this->task ? $this->task->id : null; + $notify->job_name = $this->signature; + $notify->error_message = $ex->getMessage(); + $notify->send(); - $this->info( now() ); - $this->info("Update/Create - City Information"); - $this->UpdateCities(); - $this->info( now() ); + // write message to the log + throw new Exception($ex); - // Update the Task Audit log - $task->end_time = Carbon::now(); - $task->status = 'Completed'; - $task->save(); + } return 0; @@ -77,38 +105,53 @@ protected function UpdateCities() //$filter = 'date_updated gt \''.$last_start_time.'\' or date_deleted gt \''.$last_start_time.'\''; $filter = ''; // Disbaled the filter due to process timimg issue - $response = Http::withHeaders(['Content-Type' => 'application/json']) - ->withBasicAuth(env('ODS_USERNAME'),env('ODS_TOKEN')) - ->get(env('ODS_INBOUND_PS_TGB_CITY_TBL_ENDPOINT').'?$count=true&$top=1000'.'&$filter='.$filter); - - if ($response->successful()) { - $data = json_decode($response->body())->value; - $batches = array_chunk($data, 1000); - - foreach ($batches as $key => $batch) { - $this->info( ' -- each batch (1000) $key - '. $key ); - $this->info( ' -- count batch (1000) $key - '. count($batch)); - - foreach ($batch as $row) { - City::updateOrCreate([ - 'city' => $row->City, - 'country' => $row->Country, - 'province' => $row->Province, - 'TGB_REG_DISTRICT' => $row->TGB_REG_DISTRICT, - 'DescrShort' => $row->DescrShort - ],[ - 'city' => $row->City, - 'country' => $row->Country, - 'province' => $row->Province, - 'TGB_REG_DISTRICT' => $row->TGB_REG_DISTRICT, - 'DescrShort' => $row->DescrShort - ]); + // try { + + $response = Http::withHeaders(['Content-Type' => 'application/json']) + ->withBasicAuth(env('ODS_USERNAME'),env('ODS_TOKEN')) + ->get(env('ODS_INBOUND_PS_TGB_CITY_TBL_ENDPOINT').'?$count=true&$top=1000'.'&$filter='.$filter); + + if ($response->successful()) { + $data = json_decode($response->body())->value; + $batches = array_chunk($data, 1000); + + foreach ($batches as $key => $batch) { + $this->info( ' -- each batch (1000) $key - '. $key ); + $this->info( ' -- count batch (1000) $key - '. count($batch)); + + foreach ($batch as $row) { + City::updateOrCreate([ + 'city' => $row->City, + 'country' => $row->Country, + 'province' => $row->Province, + 'TGB_REG_DISTRICT' => $row->TGB_REG_DISTRICT, + 'DescrShort' => $row->DescrShort + ],[ + 'city' => $row->City, + 'country' => $row->Country, + 'province' => $row->Province, + 'TGB_REG_DISTRICT' => $row->TGB_REG_DISTRICT, + 'DescrShort' => $row->DescrShort + ]); + } } + } else { + $this->info( $response->status() ); + $this->info( $response->body() ); } - } else { - $this->info( $response->status() ); - $this->info( $response->body() ); - } + + // } catch (\Exception $ex) { + + // // log message in system + // $this->task->status = 'Error'; + // $this->task->end_time = Carbon::now(); + // $this->task->message = $ex->getMessage() . PHP_EOL; + // $this->task->save(); + + // throw new Exception($ex); + + // } + } diff --git a/app/Console/Commands/ImportDepartments.php b/app/Console/Commands/ImportDepartments.php index e7ee41b1..7a25a62d 100644 --- a/app/Console/Commands/ImportDepartments.php +++ b/app/Console/Commands/ImportDepartments.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use Carbon\Carbon; +use Exception; use App\Models\Department; use App\Models\BusinessUnit; @@ -27,6 +28,7 @@ class ImportDepartments extends Command protected $description = 'Load Departments from BI'; /* attributes for share in the command */ + protected $task; protected $message; protected $status; @@ -52,23 +54,48 @@ public function __construct() public function handle() { - $this->task = ScheduleJobAudit::Create([ - 'job_name' => $this->signature, - 'start_time' => Carbon::now(), - 'status' => 'Processing', - ]); + try { - $this->LogMessage( now() ); - $this->LogMessage("Task-- Update/Create - Department"); - $this->UpdateDepartment(); + $this->task = ScheduleJobAudit::Create([ + 'job_name' => $this->signature, + 'start_time' => Carbon::now(), + 'status' => 'Processing', + ]); - $this->LogMessage( now() ); + $this->LogMessage( now() ); + $this->LogMessage("Task-- Update/Create - Department"); + $this->UpdateDepartment(); - // Update the Task Audit log - $this->task->end_time = Carbon::now(); - $this->task->status = $this->status; - $this->task->message = $this->message; - $this->task->save(); + $this->LogMessage( now() ); + + // Update the Task Audit log + $this->task->end_time = Carbon::now(); + $this->task->status = $this->status; + $this->task->message = $this->message; + $this->task->save(); + + + } catch (\Exception $ex) { + + // log message in system + if ($this->task) { + $this->task->status = 'Error'; + $this->task->end_time = Carbon::now(); + $this->task->message .= $ex->getMessage() . PHP_EOL; + $this->task->save(); + } + + // send out email notification + $notify = new \App\MicrosoftGraph\SendEmailNotification(); + $notify->job_id = $this->task ? $this->task->id : null; + $notify->job_name = $this->signature; + $notify->error_message = $ex->getMessage(); + $notify->send(); + + // write message to the log + throw new Exception($ex); + + } return 0; } @@ -80,62 +107,54 @@ protected function UpdateDepartment() $created_count = 0; $updated_count = 0; - try { - $response = Http::withHeaders(['Content-Type' => 'application/json']) - ->withBasicAuth(env('ODS_USERNAME'),env('ODS_TOKEN')) - ->get(env('ODS_INBOUND_REPORT_DEPARTMENTS_BI_ENDPOINT')); - - if ($response->successful()) { - $size = 1000; - $data = json_decode($response->body())->value; - $batches = array_chunk($data, $size); - - foreach ($batches as $key => $batch) { - $this->LogMessage( ' -- each batch ('.$size.') $key - '. $key ); - foreach ($batch as $row) { - - $business_unit = BusinessUnit::where('code', $row->business_unit_code)->first(); - - $rec = Department::updateOrCreate([ - 'bi_department_id' => $row->department_id, - ], [ - 'department_name' => $row->department_name, - 'group' => $row->group, - 'yearcd' => $row->yearcd, - 'business_unit_code'=> $row->business_unit_code, - 'business_unit_name' => $row->business_unit_name, - 'business_unit_id' => $business_unit ? $business_unit->id : null, - ]); - - $total_count += 1; - - if ($rec->wasRecentlyCreated) { - $created_count += 1; - } elseif ($rec->wasChanged() ) { - $updated_count += 1; - } else { - // No Action - } - + $response = Http::withHeaders(['Content-Type' => 'application/json']) + ->withBasicAuth(env('ODS_USERNAME'),env('ODS_TOKEN')) + ->get(env('ODS_INBOUND_REPORT_DEPARTMENTS_BI_ENDPOINT')); + + if ($response->successful()) { + $size = 1000; + $data = json_decode($response->body())->value; + $batches = array_chunk($data, $size); + + foreach ($batches as $key => $batch) { + $this->LogMessage( ' -- each batch ('.$size.') $key - '. $key ); + foreach ($batch as $row) { + + $business_unit = BusinessUnit::where('code', $row->business_unit_code)->first(); + + $rec = Department::updateOrCreate([ + 'bi_department_id' => $row->department_id, + ], [ + 'department_name' => $row->department_name, + 'group' => $row->group, + 'yearcd' => $row->yearcd, + 'business_unit_code'=> $row->business_unit_code, + 'business_unit_name' => $row->business_unit_name, + 'business_unit_id' => $business_unit ? $business_unit->id : null, + ]); + + $total_count += 1; + + if ($rec->wasRecentlyCreated) { + $created_count += 1; + } elseif ($rec->wasChanged() ) { + $updated_count += 1; + } else { + // No Action } - } - - $this->LogMessage(' Total Row count : ' . $total_count ); - $this->LogMessage(' Total Created count : ' . $created_count ); - $this->LogMessage(' Total Updated count : ' . $updated_count ); - } else { - $this->status = 'Error'; - $this->LogMessage( $response->status() . ' - ' . $response->body() ); + } } - } catch (\Exception $ex) { - // write to log message - $this->status = 'Error'; - $this->LogMessage( $ex->getMessage() ); + $this->LogMessage(' Total Row count : ' . $total_count ); + $this->LogMessage(' Total Created count : ' . $created_count ); + $this->LogMessage(' Total Updated count : ' . $updated_count ); - return 1; + } else { + $this->status = 'Error'; + $this->LogMessage( $response->status() . ' - ' . $response->body() ); } + } protected function LogMessage($text) diff --git a/app/Console/Commands/ImportEmployeeJob.php b/app/Console/Commands/ImportEmployeeJob.php index 222c4d38..c69f86c0 100644 --- a/app/Console/Commands/ImportEmployeeJob.php +++ b/app/Console/Commands/ImportEmployeeJob.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use Carbon\Carbon; +use Exception; use App\Models\EmployeeJob; use App\Models\PledgeHistory; use Illuminate\Console\Command; @@ -30,6 +31,7 @@ class ImportEmployeeJob extends Command const MAX_UPDATE_COUNT = 1000; /* attributes for share in the command */ + protected $task; protected $total_count; protected $created_count; protected $updated_count; @@ -64,27 +66,51 @@ public function handle() { ini_set('memory_limit', '4096M'); - $this->task = ScheduleJobAudit::Create([ - 'job_name' => $this->signature, - 'start_time' => Carbon::now(), - 'status' => 'Processing', - ]); - - $this->LogMessage( now() ); - $this->LogMessage("Update/Create - Employee Job Information"); - $this->UpdateEmployeeJob(); - $this->LogMessage( now() ); - - if ($this->created_count > self::MAX_CREATE_COUNT) { - $this->LogMessage( '' ); - $this->LogMessage( '*NOTE: more than ' . self::MAX_CREATE_COUNT . ' new row found, only the first ' . self::MAX_CREATE_COUNT . ' lines detail were shown in the log'); - $this->LogMessage( '' ); - } + try { + + $this->task = ScheduleJobAudit::Create([ + 'job_name' => $this->signature, + 'start_time' => Carbon::now(), + 'status' => 'Processing', + ]); + + $this->LogMessage( now() ); + $this->LogMessage("Update/Create - Employee Job Information"); + $this->UpdateEmployeeJob(); + $this->LogMessage( now() ); + + if ($this->created_count > self::MAX_CREATE_COUNT) { + $this->LogMessage( '' ); + $this->LogMessage( '*NOTE: more than ' . self::MAX_CREATE_COUNT . ' new row found, only the first ' . self::MAX_CREATE_COUNT . ' lines detail were shown in the log'); + $this->LogMessage( '' ); + } + + if ($this->updated_count > self::MAX_UPDATE_COUNT) { + $this->LogMessage( '' ); + $this->LogMessage( '*NOTE: more than ' . self::MAX_UPDATE_COUNT . ' changes found, only the first ' . self::MAX_UPDATE_COUNT . ' lines detail were shown in the log'); + $this->LogMessage( '' ); + } + + } catch (\Exception $ex) { + + // log message in system + if ($this->task) { + $this->task->status = 'Error'; + $this->task->end_time = Carbon::now(); + $this->task->message .= $ex->getMessage() . PHP_EOL; + $this->task->save(); + } + + // send out email notification + $notify = new \App\MicrosoftGraph\SendEmailNotification(); + $notify->job_id = $this->task ? $this->task->id : null; + $notify->job_name = $this->signature; + $notify->error_message = $ex->getMessage(); + $notify->send(); + + // write message to the log + throw new Exception($ex); - if ($this->updated_count > self::MAX_UPDATE_COUNT) { - $this->LogMessage( '' ); - $this->LogMessage( '*NOTE: more than ' . self::MAX_UPDATE_COUNT . ' changes found, only the first ' . self::MAX_UPDATE_COUNT . ' lines detail were shown in the log'); - $this->LogMessage( '' ); } $this->LogMessage( 'Total Row count : ' . $this->total_count ); @@ -148,7 +174,7 @@ protected function UpdateEmployeeJob() $top = $size; $skip = $size * $i; - try { + // try { // Loading pledge history data $response = Http::withHeaders(['Content-Type' => 'application/json']) ->withBasicAuth(env('ODS_USERNAME'),env('ODS_TOKEN')) @@ -289,14 +315,14 @@ protected function UpdateEmployeeJob() } - } catch (\Exception $ex) { + // } catch (\Exception $ex) { - // write to log message - $this->status = 'Error'; - $this->LogMessage( $ex->getMessage() ); + // // write to log message + // $this->status = 'Error'; + // $this->LogMessage( $ex->getMessage() ); - return 1; - } + // return 1; + // } } diff --git a/app/Console/Commands/ImportNonGovPledgeHistory.php b/app/Console/Commands/ImportNonGovPledgeHistory.php index 34aa9a19..09056ab9 100644 --- a/app/Console/Commands/ImportNonGovPledgeHistory.php +++ b/app/Console/Commands/ImportNonGovPledgeHistory.php @@ -4,6 +4,7 @@ use stdClass; use Carbon\Carbon; +use Exception; use Illuminate\Console\Command; use App\Models\ScheduleJobAudit; use Illuminate\Support\Facades\DB; @@ -27,10 +28,11 @@ class ImportNonGovPledgeHistory extends Command */ protected $description = 'Import the Non Gov Pledge History data from BI'; - /* Variable for logging */ - protected $message; - protected $status; - protected $row_count; + /* Variable for logging */ + protected $task; + protected $message; + protected $status; + protected $row_count; /** * Create a new command instance. @@ -54,34 +56,58 @@ public function __construct() */ public function handle() { - // Determine the start year - $last_task = ScheduleJobAudit::where('job_name', $this->signature) - ->where('status', 'Completed') - ->first(); - - $start_year = 2005; - if ($last_task) { - $start_year = (now()->month <= 3) ? now()->year - 2 : now()->year - 1; - } + try { + + $this->task = ScheduleJobAudit::Create([ + 'job_name' => $this->signature, + 'start_time' => Carbon::now(), + 'status' => 'Processing', + ]); + + // Determine the start year + $last_task = ScheduleJobAudit::where('job_name', $this->signature) + ->where('status', 'Completed') + ->first(); + + $start_year = 2005; + if ($last_task) { + $start_year = (now()->month <= 3) ? now()->year - 2 : now()->year - 1; + } + + $this->LogMessage( now() ); + $this->LogMessage("Step - 1 : Create - Non-Gov Pledge History"); + for ($yr = $start_year; $yr <= now()->year; $yr++) { + $this->UpdateNonGovPledgeHistory($yr); + } + + $this->LogMessage( now() ); + $this->LogMessage("Step - 2 : Create - Non-Gov Pledge History Summary"); + $this->UpdatePledgeHistorySummary(); - $this->task = ScheduleJobAudit::Create([ - 'job_name' => $this->signature, - 'start_time' => Carbon::now(), - 'status' => 'Processing', - ]); + $this->LogMessage( now() ); - $this->LogMessage( now() ); - $this->LogMessage("Step - 1 : Create - Non-Gov Pledge History"); - for ($yr = $start_year; $yr <= now()->year; $yr++) { - $this->UpdateNonGovPledgeHistory($yr); - } + } catch (\Exception $ex) { - $this->LogMessage( now() ); - $this->LogMessage("Step - 2 : Create - Non-Gov Pledge History Summary"); - $this->UpdatePledgeHistorySummary(); + // log message in system + if ($this->task) { + $this->task->status = 'Error'; + $this->task->end_time = Carbon::now(); + $this->task->message = $ex->getMessage() . PHP_EOL; + $this->task->save(); + } - $this->LogMessage( now() ); + // send out email notification + $notify = new \App\MicrosoftGraph\SendEmailNotification(); + $notify->job_id = $this->task ? $this->task->id : null; + $notify->job_name = $this->signature; + $notify->error_message = $ex->getMessage(); + $notify->send(); + + // write message to the log + throw new Exception($ex); + + } // Update the Task Audit log $this->task->end_time = Carbon::now(); @@ -102,7 +128,7 @@ protected function UpdateNonGovPledgeHistory($in_year) $this->LogMessage( 'Loading pledge history data for '. $in_year); $filter = '(yearcd eq '. $in_year .')'; - try { + // try { $response = Http::withHeaders(['Content-Type' => 'application/json']) ->withBasicAuth(env('ODS_USERNAME'),env('ODS_TOKEN')) ->get(env('ODS_INBOUND_REPORT_NON_GOV_PLEDGE_HISTORY_BI_ENDPOINT') .'?$count=true&$top=1&$filter='.$filter); @@ -192,15 +218,15 @@ protected function UpdateNonGovPledgeHistory($in_year) } - } catch (\Exception $ex) { + // } catch (\Exception $ex) { - // write to log message - $this->status = 'Error'; - $this->LogMessage( $ex->getMessage() ); + // // write to log message + // $this->status = 'Error'; + // $this->LogMessage( $ex->getMessage() ); - return 1; + // return 1; - } + // } } diff --git a/app/Console/Commands/ImportPayCalendar.php b/app/Console/Commands/ImportPayCalendar.php index 7b73fb0c..0ffedf50 100644 --- a/app/Console/Commands/ImportPayCalendar.php +++ b/app/Console/Commands/ImportPayCalendar.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use Carbon\Carbon; +use Exception; use App\Models\PayCalendar; use Illuminate\Console\Command; use App\Models\ScheduleJobAudit; @@ -25,6 +26,7 @@ class ImportPayCalendar extends Command protected $description = 'Sync Pay Calendar from PeopleSoft via ODS'; /* attributes for share in the command */ + protected $task; protected $created_count; protected $updated_count; protected $message; @@ -56,27 +58,51 @@ public function __construct() */ public function handle() { - $this->task = ScheduleJobAudit::Create([ - 'job_name' => $this->signature, - 'start_time' => Carbon::now(), - 'status' => 'Processing', - ]); - - $this->LogMessage( now() ); - $this->LogMessage("Task -- Update/Create - Pay Calendar"); - $this->UpdatePayCalendar(); - $this->LogMessage( now() ); - - $this->LogMessage( '' ); - $this->LogMessage( 'Total new created row(s) : ' . $this->created_count ); - $this->LogMessage( 'Total Updated row(s) : ' . $this->updated_count ); - $this->LogMessage( '' ); - - // Update the Task Audit log - $this->task->end_time = Carbon::now(); - $this->task->status = $this->status; - $this->task->message = $this->message; - $this->task->save(); + try { + + $this->task = ScheduleJobAudit::Create([ + 'job_name' => $this->signature, + 'start_time' => Carbon::now(), + 'status' => 'Processing', + ]); + + $this->LogMessage( now() ); + $this->LogMessage("Task -- Update/Create - Pay Calendar"); + $this->UpdatePayCalendar(); + $this->LogMessage( now() ); + + $this->LogMessage( '' ); + $this->LogMessage( 'Total new created row(s) : ' . $this->created_count ); + $this->LogMessage( 'Total Updated row(s) : ' . $this->updated_count ); + $this->LogMessage( '' ); + + // Update the Task Audit log + $this->task->end_time = Carbon::now(); + $this->task->status = $this->status; + $this->task->message = $this->message; + $this->task->save(); + + } catch (\Exception $ex) { + + // log message in system + if ($this->task) { + $this->task->status = 'Error'; + $this->task->end_time = Carbon::now(); + $this->task->message .= $ex->getMessage() . PHP_EOL; + $this->task->save(); + } + + // send out email notification + $notify = new \App\MicrosoftGraph\SendEmailNotification(); + $notify->job_id = $this->task ? $this->task->id : null; + $notify->job_name = $this->signature; + $notify->error_message = $ex->getMessage(); + $notify->send(); + + // write message to the log + throw new Exception($ex); + + } return 0; } @@ -84,7 +110,7 @@ public function handle() protected function UpdatePayCalendar() { - try { + // try { $response = Http::withHeaders(['Content-Type' => 'application/json']) ->withBasicAuth(env('ODS_USERNAME'),env('ODS_TOKEN')) ->get(env('ODS_INBOUND_PAY_CALENDAR_BI_ENDPOINT')); @@ -129,14 +155,14 @@ protected function UpdatePayCalendar() $this->status = 'Error'; $this->LogMessage( $response->status() . ' - ' . $response->body() ); } - } catch (\Exception $ex) { + // } catch (\Exception $ex) { - // write to log message - $this->status = 'Error'; - $this->LogMessage( $ex->getMessage() ); + // // write to log message + // $this->status = 'Error'; + // $this->LogMessage( $ex->getMessage() ); - return 1; - } + // return 1; + // } } diff --git a/app/Console/Commands/ImportPledgeHistory.php b/app/Console/Commands/ImportPledgeHistory.php index e3e03be9..a3efc54c 100644 --- a/app/Console/Commands/ImportPledgeHistory.php +++ b/app/Console/Commands/ImportPledgeHistory.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use Carbon\Carbon; +use Exception; use App\Models\PledgeHistory; use Illuminate\Console\Command; // use App\Models\RegionalDistrict; @@ -29,6 +30,7 @@ class ImportPledgeHistory extends Command protected $description = 'Import the Pledge Hostory data from BI'; /* Variable for logging */ + protected $task; protected $message; protected $status; protected $reload_start_year; @@ -56,40 +58,66 @@ public function __construct() public function handle() { - // Determine the start year - $last_task = ScheduleJobAudit::where('job_name', $this->signature) - ->where('status', 'Completed') - ->first(); + try { - $start_year = 2005; - if ($last_task) { - $start_year = (now()->month <= 3) ? now()->year - 2 : now()->year - 1; - } + $this->task = ScheduleJobAudit::Create([ + 'job_name' => $this->signature, + 'start_time' => Carbon::now(), + 'status' => 'Processing', + ]); + + // Determine the start year + $last_task = ScheduleJobAudit::where('job_name', $this->signature) + ->where('status', 'Completed') + ->first(); - $this->task = ScheduleJobAudit::Create([ - 'job_name' => $this->signature, - 'start_time' => Carbon::now(), - 'status' => 'Processing', - ]); + $start_year = 2005; + if ($last_task) { + $start_year = (now()->month <= 3) ? now()->year - 2 : now()->year - 1; + } - // $this->LogMessage( now() ); - // $this->LogMessage("Step - 1 : Update/Create - Region District"); - // $this->UpdateRegionalDistrict(); - $this->LogMessage( now() ); - $this->LogMessage("Step - 1 : Reload - Pledge History Vendor"); - $this->UpdatePledgeHistoryVendor(); - - $this->LogMessage( now() ); - $this->LogMessage("Step - 2 : Reload - Pledge History"); - for ($yr = $start_year; $yr <= now()->year; $yr++) { - $this->UpdatePledgeHistory($yr); - } - $this->LogMessage( now() ); - $this->LogMessage("Step - 3 : Reload - Pledge History Summary"); - $this->UpdatePledgeHistorySummary(); - $this->LogMessage( now() ); + // $this->LogMessage( now() ); + // $this->LogMessage("Step - 1 : Update/Create - Region District"); + // $this->UpdateRegionalDistrict(); + + $this->LogMessage( now() ); + $this->LogMessage("Step - 1 : Reload - Pledge History Vendor"); + $this->UpdatePledgeHistoryVendor(); + + $this->LogMessage( now() ); + $this->LogMessage("Step - 2 : Reload - Pledge History"); + for ($yr = $start_year; $yr <= now()->year; $yr++) { + $this->UpdatePledgeHistory($yr); + } + $this->LogMessage( now() ); + $this->LogMessage("Step - 3 : Reload - Pledge History Summary"); + $this->UpdatePledgeHistorySummary(); + + $this->LogMessage( now() ); + + } catch (\Exception $ex) { + + // log message in system + if ($this->task) { + $this->task->status = 'Error'; + $this->task->end_time = Carbon::now(); + $this->task->message = $ex->getMessage() . PHP_EOL; + $this->task->save(); + } + + // send out email notification + $notify = new \App\MicrosoftGraph\SendEmailNotification(); + $notify->job_id = $this->task ? $this->task->id : null; + $notify->job_name = $this->signature; + $notify->error_message = $ex->getMessage(); + $notify->send(); + + // write message to the log + throw new Exception($ex); + + } // Update the Task Audit log $this->task->end_time = Carbon::now(); @@ -157,7 +185,7 @@ public function handle() protected function UpdatePledgeHistoryVendor() { - try { + // try { $response = Http::withHeaders(['Content-Type' => 'application/json']) ->withBasicAuth(env('ODS_USERNAME'),env('ODS_TOKEN')) ->get(env('ODS_INBOUND_REPORT_PLEDGE_HISTORY_VNDR_BI_ENDPOINT') .'?$count=true&$top=1'); @@ -223,14 +251,14 @@ protected function UpdatePledgeHistoryVendor() } - } catch (\Exception $ex) { + // } catch (\Exception $ex) { - $this->status = 'Error'; - $this->LogMessage( $ex->getMessage() ); + // $this->status = 'Error'; + // $this->LogMessage( $ex->getMessage() ); - return 1; + // return 1; - } + // } } @@ -242,7 +270,7 @@ protected function UpdatePledgeHistory($in_year) $this->LogMessage( 'Loading pledge history data for '. $in_year); $filter = '(yearcd eq '. $in_year .')'; - try { + // try { $response = Http::withHeaders(['Content-Type' => 'application/json']) ->withBasicAuth(env('ODS_USERNAME'),env('ODS_TOKEN')) ->get(env('ODS_INBOUND_REPORT_PLEDGE_HISTORY_BI_ENDPOINT') .'?$count=true&$top=1&$filter='.$filter); @@ -348,15 +376,15 @@ protected function UpdatePledgeHistory($in_year) } - } catch (\Exception $ex) { + // } catch (\Exception $ex) { - // write to log message - $this->status = 'Error'; - $this->LogMessage( $ex->getMessage() ); + // // write to log message + // $this->status = 'Error'; + // $this->LogMessage( $ex->getMessage() ); - return 1; + // return 1; - } + // } } protected function UpdatePledgeHistorySummary() { diff --git a/app/Console/Commands/SyncUserProfile.php b/app/Console/Commands/SyncUserProfile.php index f2318f24..c836a982 100644 --- a/app/Console/Commands/SyncUserProfile.php +++ b/app/Console/Commands/SyncUserProfile.php @@ -4,6 +4,7 @@ use DateTime; use Carbon\Carbon; +use Exception; use App\Models\User; use App\Models\EmployeeJob; use App\Models\Organization; @@ -35,6 +36,7 @@ class SyncUserProfile extends Command /* Source Type is HCM */ protected const SOURCE_TYPE = 'HCM'; + protected $task; protected $created_count; protected $updated_count; protected $locked_count; @@ -71,27 +73,51 @@ public function __construct() public function handle() { - $this->task = ScheduleJobAudit::Create([ - 'job_name' => $this->signature, - 'start_time' => Carbon::now(), - 'status' => 'Processing', - ]); + try { - $this->LogMessage( now() ); - $this->LogMessage("Update/Create - User Profile"); - $this->SyncUserProfile(); - $this->LogMessage( now() ); - - if ($this->created_count > self::MAX_CREATE_COUNT) { - $this->LogMessage( '' ); - $this->LogMessage( '*NOTE: more than ' . self::MAX_CREATE_COUNT . ' new row found, only the first ' . self::MAX_CREATE_COUNT . ' lines detail were shown in the log'); - $this->LogMessage( '' ); - } + $this->task = ScheduleJobAudit::Create([ + 'job_name' => $this->signature, + 'start_time' => Carbon::now(), + 'status' => 'Processing', + ]); + + $this->LogMessage( now() ); + $this->LogMessage("Update/Create - User Profile"); + $this->SyncUserProfile(); + $this->LogMessage( now() ); + + if ($this->created_count > self::MAX_CREATE_COUNT) { + $this->LogMessage( '' ); + $this->LogMessage( '*NOTE: more than ' . self::MAX_CREATE_COUNT . ' new row found, only the first ' . self::MAX_CREATE_COUNT . ' lines detail were shown in the log'); + $this->LogMessage( '' ); + } + + if ($this->updated_count > self::MAX_UPDATE_COUNT) { + $this->LogMessage( '' ); + $this->LogMessage( '*NOTE: more than ' . self::MAX_UPDATE_COUNT . ' changes found, only the first ' . self::MAX_UPDATE_COUNT . ' lines detail were shown in the log'); + $this->LogMessage( '' ); + } + + } catch (\Exception $ex) { + + // log message in system + if ($this->task) { + $this->task->status = 'Error'; + $this->task->end_time = Carbon::now(); + $this->task->message .= $ex->getMessage() . PHP_EOL; + $this->task->save(); + } + + // send out email notification + $notify = new \App\MicrosoftGraph\SendEmailNotification(); + $notify->job_id = $this->task ? $this->task->id : null; + $notify->job_name = $this->signature; + $notify->error_message = $ex->getMessage(); + $notify->send(); + + // write message to the log + throw new Exception($ex); - if ($this->updated_count > self::MAX_UPDATE_COUNT) { - $this->LogMessage( '' ); - $this->LogMessage( '*NOTE: more than ' . self::MAX_UPDATE_COUNT . ' changes found, only the first ' . self::MAX_UPDATE_COUNT . ' lines detail were shown in the log'); - $this->LogMessage( '' ); } $this->LogMessage( 'Total new created row(s) : ' . $this->created_count ); @@ -175,8 +201,6 @@ protected function SyncUserProfile() // reach here mean No Differece found -- no action required } else { - try { - $user->source_type = self::SOURCE_TYPE; $user->email = $target_email; $user->idir = $employee->idir; @@ -193,13 +217,6 @@ protected function SyncUserProfile() $this->LogMessage(' summary => '. json_encode( $changes ) ); } - } catch(\Illuminate\Database\QueryException $ex){ - - $this->status = 'Error'; - $this->LogMessage('Exception -- ' . $ex->getMessage() ); - - } - } } else { diff --git a/app/Console/Commands/UpdateDailyCampaign.php b/app/Console/Commands/UpdateDailyCampaign.php index 0e61ddc3..175e41f1 100644 --- a/app/Console/Commands/UpdateDailyCampaign.php +++ b/app/Console/Commands/UpdateDailyCampaign.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use Carbon\Carbon; +use Exception; use App\Models\Region; use App\Models\Setting; use App\Models\BusinessUnit; @@ -30,6 +31,8 @@ class UpdateDailyCampaign extends Command */ protected $description = 'Update Daily Campaign Statistics and stored in the daily_campaigns table'; + protected $task; + /** * Create a new command instance. * @@ -50,16 +53,41 @@ public function __construct() */ public function handle() { - $this->task = ScheduleJobAudit::Create([ - 'job_name' => $this->signature, - 'start_time' => Carbon::now(), - 'status' => 'Processing', - ]); - - $this->LogMessage( now() ); - $this->LogMessage("Task -- Update Daily Campaign Statistics and stored in the daily_campaigns table'"); - $this->storeDailyCampaign(); - $this->LogMessage( now() ); + + try { + + $this->task = ScheduleJobAudit::Create([ + 'job_name' => $this->signature, + 'start_time' => Carbon::now(), + 'status' => 'Processing', + ]); + + $this->LogMessage( now() ); + $this->LogMessage("Task -- Update Daily Campaign Statistics and stored in the daily_campaigns table'"); + $this->storeDailyCampaign(); + $this->LogMessage( now() ); + + } catch (\Exception $ex) { + + // log message in system + if ($this->task) { + $this->task->status = 'Error'; + $this->task->end_time = Carbon::now(); + $this->task->message .= $ex->getMessage() . PHP_EOL; + $this->task->save(); + } + + // send out email notification + $notify = new \App\MicrosoftGraph\SendEmailNotification(); + $notify->job_id = $this->task ? $this->task->id : null; + $notify->job_name = $this->signature; + $notify->error_message = $ex->getMessage(); + $notify->send(); + + // write message to the log + throw new Exception($ex); + + } // Update the Task Audit log $this->task->end_time = Carbon::now(); diff --git a/app/Console/Commands/UpdateEligibleEmployeeSnapshot.php b/app/Console/Commands/UpdateEligibleEmployeeSnapshot.php index c87e8f20..d1e2272d 100644 --- a/app/Console/Commands/UpdateEligibleEmployeeSnapshot.php +++ b/app/Console/Commands/UpdateEligibleEmployeeSnapshot.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use Carbon\Carbon; +use Exception; use App\Models\Setting; use App\Models\EmployeeJob; use App\Models\BusinessUnit; @@ -29,6 +30,8 @@ class UpdateEligibleEmployeeSnapshot extends Command */ protected $description = 'To take a snapshot of the Eligible Employee, optional --date YYYY-MM-DD to collect for the current as specified date'; + protected $task; + /** * Create a new command instance. * @@ -55,11 +58,35 @@ public function handle() 'status' => 'Processing', ]); - $this->LogMessage( now() ); - $this->LogMessage("Task -- Capture a snapshot of Eligible Employee with region, business unit, department"); - $this->storeEligibleEmployeeDetail(); - $this->LogMessage( now() ); + try { + + $this->LogMessage( now() ); + $this->LogMessage("Task -- Capture a snapshot of Eligible Employee with region, business unit, department"); + $this->storeEligibleEmployeeDetail(); + $this->LogMessage( now() ); + + } catch (\Exception $ex) { + + // log message in system + if ($this->task) { + $this->task->status = 'Error'; + $this->task->end_time = Carbon::now(); + $this->task->message .= $ex->getMessage() . PHP_EOL; + $this->task->save(); + } + // send out email notification + $notify = new \App\MicrosoftGraph\SendEmailNotification(); + $notify->job_id = $this->task ? $this->task->id : null; + $notify->job_name = $this->signature; + $notify->error_message = $ex->getMessage(); + $notify->send(); + + // write message to the log + throw new Exception($ex); + + } + // Update the Task Audit log $this->task->end_time = Carbon::now(); $this->task->status = $this->status; diff --git a/app/Mail/NotifyMail.php b/app/Mail/NotifyMail.php new file mode 100644 index 00000000..de9ce492 --- /dev/null +++ b/app/Mail/NotifyMail.php @@ -0,0 +1,43 @@ +from = $from; + $this->subject = $subject; + $this->body = $body; + $this->from_email = $from_email; + + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + return $this->from( $this->from_email ) + ->subject( $this->subject ) + ->view('emails.notification-template'); + } +} diff --git a/app/MicrosoftGraph/SendEmailNotification.php b/app/MicrosoftGraph/SendEmailNotification.php new file mode 100644 index 00000000..6bf3101d --- /dev/null +++ b/app/MicrosoftGraph/SendEmailNotification.php @@ -0,0 +1,102 @@ +toRecipients = []; + $this->ccRecipients = []; + $this->bccRecipients = []; + + $this->subject = ''; + $this->body = ''; + + $this->job_id = ''; + $this->job_name = ''; + $this->error_message = ''; + + $this->bodyContentType = 'html'; + $this->saveToLog = true; + + } + + public function send() + { + + $switch = env('EMAIL_NOTIFICATION_ENABLED'); + if (!($switch)) { + return true; + } + + $this->toRecipients = env('EMAIL_NOTIFICATION_EMAIL_ADDRESSES'); + + return $this->sendMailUsingSMPTServer(); + + } + + protected function sendMailUsingSMPTServer() + { + + $this->subject = "PECSF [". App::environment() . "] -- The Process ('" . $this->job_id . " - ". $this->job_name . ")' was failed to complete."; + + $this->body = "
"; + $this->body .= "Process ID : " . $this->job_id . ""; + $this->body .= "Process Name : " . $this->job_name . ""; + $this->body .= "Failed at : " . now() . ""; + $this->body .= "
"; + $this->body .= "The process was failed with the following error message:
"; + $this->body .= "" . $this->error_message . "
"; + + // Send immediately + $from = env('MAIL_FROM_ADDRESS'); + $toAddresses = explode(",", $this->toRecipients); + $subject = $this->subject; + $body = $this->body; + + Mail::to( $toAddresses )->send(new NotifyMail( $from, $subject, $body )); + + if ($this->saveToLog) { + // append onto Notification log file + Log::channel('smtp')->info("Process (" . $this->job_id . " - ". $this->job_name . ") failure notification message sent out to " . $this->toRecipients ); + + } + + return true; + + } + +} diff --git a/config/logging.php b/config/logging.php index 1aa06aa3..cbc7472d 100644 --- a/config/logging.php +++ b/config/logging.php @@ -37,7 +37,7 @@ 'channels' => [ 'stack' => [ 'driver' => 'stack', - 'channels' => ['single'], + 'channels' => ['daily'], 'ignore_exceptions' => false, ], @@ -51,7 +51,12 @@ 'driver' => 'daily', 'path' => storage_path('logs/laravel.log'), 'level' => env('LOG_LEVEL', 'debug'), - 'days' => 14, + 'days' => 28, + ], + + 'smtp' => [ + 'driver' => 'single', + 'path' => storage_path('logs/smtp.log'), ], 'slack' => [ diff --git a/resources/views/emails/notification-template.blade.php b/resources/views/emails/notification-template.blade.php new file mode 100644 index 00000000..aab1b854 --- /dev/null +++ b/resources/views/emails/notification-template.blade.php @@ -0,0 +1,9 @@ + + + +