From da30ed6bdb3a95719c4b146ef642aa4d79151acd Mon Sep 17 00:00:00 2001 From: George Walker Date: Fri, 30 Apr 2021 13:41:00 -0700 Subject: [PATCH] Add try catch to queue processing logic --- .../ClientApp/extra-webpack.config.js | 4 +- one-stop-service/OneStopUtils.cs | 138 ++++++++++-------- openshift/backup.sh | 1 - 3 files changed, 80 insertions(+), 63 deletions(-) diff --git a/cllc-public-app/ClientApp/extra-webpack.config.js b/cllc-public-app/ClientApp/extra-webpack.config.js index ce02583eca..471324d853 100644 --- a/cllc-public-app/ClientApp/extra-webpack.config.js +++ b/cllc-public-app/ClientApp/extra-webpack.config.js @@ -45,8 +45,8 @@ module.exports = { options: { presets: ['@babel/preset-env'], plugins: ['@babel/plugin-transform-runtime'], - cacheDirectory: false, - cacheCompression: false + cacheDirectory: true, + cacheCompression: true } diff --git a/one-stop-service/OneStopUtils.cs b/one-stop-service/OneStopUtils.cs index fd001cc7d5..1b16c89072 100644 --- a/one-stop-service/OneStopUtils.cs +++ b/one-stop-service/OneStopUtils.cs @@ -493,74 +493,92 @@ public async Task CheckForNewLicences(PerformContext hangfireContext) var item = dynamicsClient.GetLicenceByIdWithChildren(queueItem._adoxioLicenceValue); string licenceId = item.AdoxioLicencesid; - - switch ((OneStopHubStatusChange)queueItem.AdoxioStatuschangedescription) + try { - case OneStopHubStatusChange.Issued: - case OneStopHubStatusChange.TransferComplete: - if ((OneStopHubStatusChange)queueItem.AdoxioStatuschangedescription == - OneStopHubStatusChange.TransferComplete) - { - // send a change status to the old licensee - await SendChangeStatusRest(hangfireContext, licenceId, - (OneStopHubStatusChange)queueItem.AdoxioStatuschangedescription, queueItem.AdoxioOnestopmessageitemid); - } - // Do not attempt to send licence records that have no establishment (for example, Marketer Licence records) - if (item.AdoxioEstablishment != null) - { - - string programAccountCode = "001"; - if (item.AdoxioBusinessprogramaccountreferencenumber != null) - { - programAccountCode = item.AdoxioBusinessprogramaccountreferencenumber; - } - // set the maximum code. - string cacheKey = "_BPAR_" + item.AdoxioLicencesid; - string suffix = programAccountCode.TrimStart('0'); - if (int.TryParse(suffix, out int newNumber)) - { - newNumber += 10; // 10 tries. - } - else + + switch ((OneStopHubStatusChange) queueItem.AdoxioStatuschangedescription) + { + case OneStopHubStatusChange.Issued: + case OneStopHubStatusChange.TransferComplete: + if ((OneStopHubStatusChange) queueItem.AdoxioStatuschangedescription == + OneStopHubStatusChange.TransferComplete) { - newNumber = 10; + // send a change status to the old licensee + await SendChangeStatusRest(hangfireContext, licenceId, + (OneStopHubStatusChange) queueItem.AdoxioStatuschangedescription, + queueItem.AdoxioOnestopmessageitemid); } - _cache.Set(cacheKey, newNumber); - if (hangfireContext != null) + // Do not attempt to send licence records that have no establishment (for example, Marketer Licence records) + if (item.AdoxioEstablishment != null) { - hangfireContext.WriteLine($"SET key {cacheKey} to {newNumber}"); + + string programAccountCode = "001"; + if (item.AdoxioBusinessprogramaccountreferencenumber != null) + { + programAccountCode = item.AdoxioBusinessprogramaccountreferencenumber; + } + + // set the maximum code. + string cacheKey = "_BPAR_" + item.AdoxioLicencesid; + string suffix = programAccountCode.TrimStart('0'); + if (int.TryParse(suffix, out int newNumber)) + { + newNumber += 10; // 10 tries. + } + else + { + newNumber = 10; + } + + _cache.Set(cacheKey, newNumber); + + if (hangfireContext != null) + { + hangfireContext.WriteLine($"SET key {cacheKey} to {newNumber}"); + } + + await SendProgramAccountRequestREST(hangfireContext, licenceId, suffix, + queueItem.AdoxioOnestopmessageitemid); + } - await SendProgramAccountRequestREST(hangfireContext, licenceId, suffix, queueItem.AdoxioOnestopmessageitemid); - - } - - break; - case OneStopHubStatusChange.Cancelled: - case OneStopHubStatusChange.EnteredDormancy: - case OneStopHubStatusChange.DormancyEnded: - case OneStopHubStatusChange.Expired: - case OneStopHubStatusChange.CancellationRemoved: - case OneStopHubStatusChange.Renewed: - case OneStopHubStatusChange.Suspended: - case OneStopHubStatusChange.SuspensionEnded: - - await SendChangeStatusRest(hangfireContext, licenceId, - (OneStopHubStatusChange)queueItem.AdoxioStatuschangedescription, queueItem.AdoxioOnestopmessageitemid); - break; - - case OneStopHubStatusChange.ChangeOfAddress: - await SendChangeAddressRest(hangfireContext, licenceId, queueItem.AdoxioOnestopmessageitemid); - break; - case OneStopHubStatusChange.ChangeOfName: - await SendChangeNameRest(hangfireContext, licenceId, queueItem.AdoxioOnestopmessageitemid, false); - break; - case OneStopHubStatusChange.LicenceDeemedAtTransfer: - await SendChangeNameRest(hangfireContext, licenceId, queueItem.AdoxioOnestopmessageitemid, true); - break; + + break; + case OneStopHubStatusChange.Cancelled: + case OneStopHubStatusChange.EnteredDormancy: + case OneStopHubStatusChange.DormancyEnded: + case OneStopHubStatusChange.Expired: + case OneStopHubStatusChange.CancellationRemoved: + case OneStopHubStatusChange.Renewed: + case OneStopHubStatusChange.Suspended: + case OneStopHubStatusChange.SuspensionEnded: + + await SendChangeStatusRest(hangfireContext, licenceId, + (OneStopHubStatusChange) queueItem.AdoxioStatuschangedescription, + queueItem.AdoxioOnestopmessageitemid); + break; + + case OneStopHubStatusChange.ChangeOfAddress: + await SendChangeAddressRest(hangfireContext, licenceId, + queueItem.AdoxioOnestopmessageitemid); + break; + case OneStopHubStatusChange.ChangeOfName: + await SendChangeNameRest(hangfireContext, licenceId, + queueItem.AdoxioOnestopmessageitemid, false); + break; + case OneStopHubStatusChange.LicenceDeemedAtTransfer: + await SendChangeNameRest(hangfireContext, licenceId, + queueItem.AdoxioOnestopmessageitemid, true); + break; + } + + currentItem++; + } + catch (Exception e) + { + Log.Logger.Error(e, "Unexpected Error while processing item."); } - currentItem++; if (currentItem > maxLicencesPerInterval) { diff --git a/openshift/backup.sh b/openshift/backup.sh index 70a6dff7d4..92bef71099 100644 --- a/openshift/backup.sh +++ b/openshift/backup.sh @@ -27,4 +27,3 @@ for component in ${components}; do popd >/dev/null done -echo "DONE. SETTINGSFOLDER is ${SETTINGSFOLDER}" \ No newline at end of file