From 23851e89971b906214d063a41c776b5acc276ba5 Mon Sep 17 00:00:00 2001 From: jp-Telus <86217312+jp-Telus@users.noreply.github.com> Date: Tue, 30 May 2023 21:29:25 -0700 Subject: [PATCH] Dev - System Notification in the Event of Data Interface Errors [jp-0002] (additional improvements) --- .../Commands/ImportNonGovPledgeHistory.php | 17 ++++++++-- app/Console/Commands/ImportPledgeHistory.php | 32 ++++++++++++++----- app/MicrosoftGraph/SendEmailNotification.php | 2 +- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/app/Console/Commands/ImportNonGovPledgeHistory.php b/app/Console/Commands/ImportNonGovPledgeHistory.php index 9c026960..a6d33011 100644 --- a/app/Console/Commands/ImportNonGovPledgeHistory.php +++ b/app/Console/Commands/ImportNonGovPledgeHistory.php @@ -129,9 +129,11 @@ protected function UpdateNonGovPledgeHistory($in_year) $filter = '(yearcd eq '. $in_year .')'; // 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); + $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); + + if ($response->successful()) { $row_count = json_decode($response->body())->{'@odata.count'}; @@ -220,6 +222,15 @@ protected function UpdateNonGovPledgeHistory($in_year) } + } else { + + $this->status = 'Error'; + $this->LogMessage( $response->status() . ' - ' . $response->body() ); + + throw new Exception( $response->status() . ' - ' . $response->body() ); + + } + // } catch (\Exception $ex) { // // write to log message diff --git a/app/Console/Commands/ImportPledgeHistory.php b/app/Console/Commands/ImportPledgeHistory.php index a672f54b..2040ad92 100644 --- a/app/Console/Commands/ImportPledgeHistory.php +++ b/app/Console/Commands/ImportPledgeHistory.php @@ -186,12 +186,13 @@ protected function UpdatePledgeHistoryVendor() { // 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'); + $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'); + if ($response->successful()) { $row_count = json_decode($response->body())->{'@odata.count'}; - + if ($row_count > 0) { // Truncate Pledge History table when records returned from BI PledgeHistoryVendor::truncate(); @@ -252,6 +253,14 @@ protected function UpdatePledgeHistoryVendor() } + } else { + + $this->status = 'Error'; + $this->LogMessage( $response->status() . ' - ' . $response->body() ); + + throw new Exception( $response->status() . ' - ' . $response->body() ); + } + // } catch (\Exception $ex) { // $this->status = 'Error'; @@ -272,10 +281,11 @@ protected function UpdatePledgeHistory($in_year) $filter = '(yearcd eq '. $in_year .')'; // 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); + $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); + if ($response->successful()) { $row_count = json_decode($response->body())->{'@odata.count'}; $size = 10000; @@ -373,10 +383,16 @@ protected function UpdatePledgeHistory($in_year) $this->status = 'Error'; $this->LogMessage( $response->status() . ' - ' . $response->body() ); - } + throw new Exception( $response->status() . ' - ' . $response->body() ); + } } + } else { + + throw new Exception( $response->status() . ' - ' . $response->body() ); + } + // } catch (\Exception $ex) { // // write to log message diff --git a/app/MicrosoftGraph/SendEmailNotification.php b/app/MicrosoftGraph/SendEmailNotification.php index 6bf3101d..5ad45955 100644 --- a/app/MicrosoftGraph/SendEmailNotification.php +++ b/app/MicrosoftGraph/SendEmailNotification.php @@ -71,7 +71,7 @@ public function send() protected function sendMailUsingSMPTServer() { - $this->subject = "PECSF [". App::environment() . "] -- The Process ('" . $this->job_id . " - ". $this->job_name . ")' was failed to complete."; + $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 . "";