From 5bde2589e5231b413dc75c85f95e4b46cbd37a8c Mon Sep 17 00:00:00 2001 From: Alan Cruikshanks Date: Tue, 3 Dec 2024 10:11:30 +0000 Subject: [PATCH] Remove all logging and error handling TBH, I'm still not clear when and how this service will get called. But the two scenarios I think we are looking at is - when a change happens with a licence - when [New 'import' job to trigger return log and supplementary flag checks](https://github.com/DEFRA/water-abstraction-system/pull/1453) calls the service If it errors in the first scenario, we want it to blow up and the user to see it so they are not led to believe that the return logs have been generated. And if we can process 5K return logs in 3 secs, we should be able to handle a single licence in 1 sec, so I feel there is no need for the time to be logged. In the second instance, we'll be processing all 74K licences. We are only interested in those that have changed (end date added, removed or changed) but we normally see quite a number. In that case like the return logs job, we're more interested in the time for processing _all_ changed licences, not individual ones. And unlike the return logs job, it is acceptable that a return log creation failing blows up _this_ process, because we are just handling a single licence. It will be on the import job to ensure a licence blowing up doesn't prevent other licences from be processed. --- .../process-licence-return-logs.service.js | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/app/services/return-logs/process-licence-return-logs.service.js b/app/services/return-logs/process-licence-return-logs.service.js index 971c27baf0..91c6438311 100644 --- a/app/services/return-logs/process-licence-return-logs.service.js +++ b/app/services/return-logs/process-licence-return-logs.service.js @@ -5,7 +5,7 @@ * @module ProcessLicenceReturnLogsService */ -const { calculateAndLogTimeTaken, currentTimeInNanoseconds, timestampForPostgres } = require('../../lib/general.lib.js') +const { timestampForPostgres } = require('../../lib/general.lib.js') const FetchReturnRequirementsService = require('./fetch-return-requirements.service.js') const GenerateReturnLogService = require('./generate-return-log.service.js') const ReturnCycleModel = require('../../models/return-cycle.model.js') @@ -19,28 +19,20 @@ const VoidReturnLogsService = require('./void-return-logs.service.js') * @param {Date} [endDate] - An optional end date to use when determining which return logs to void and reissue */ async function go(licenceReference, endDate = null) { - try { - const startTime = currentTimeInNanoseconds() - - if (endDate) { - await VoidReturnLogsService.go(licenceReference, endDate) - } else { - endDate = new Date() - } + if (endDate) { + await VoidReturnLogsService.go(licenceReference, endDate) + } else { + endDate = new Date() + } - const returnCycles = await _fetchReturnCycles(endDate) + const returnCycles = await _fetchReturnCycles(endDate) - for (const returnCycle of returnCycles) { - const returnRequirements = await FetchReturnRequirementsService.go(returnCycle, licenceReference) + for (const returnCycle of returnCycles) { + const returnRequirements = await FetchReturnRequirementsService.go(returnCycle, licenceReference) - for (const returnRequirement of returnRequirements) { - await _createReturnLog(returnRequirement, returnCycle) - } + for (const returnRequirement of returnRequirements) { + await _createReturnLog(returnRequirement, returnCycle) } - - calculateAndLogTimeTaken(startTime, 'Create licence return logs job complete', { licenceReference }) - } catch (error) { - global.GlobalNotifier.omfg('Create licence return logs job failed', { error }) } }