Skip to content

Commit

Permalink
Remove all logging and error handling
Browse files Browse the repository at this point in the history
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](#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.
  • Loading branch information
Cruikshanks committed Dec 6, 2024
1 parent 9d04f7e commit 5bde258
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions app/services/return-logs/process-licence-return-logs.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 })
}
}

Expand Down

0 comments on commit 5bde258

Please sign in to comment.