Skip to content

Commit

Permalink
Rename Import job as Licence Changes and refactor (#1593)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4728

After completing [Remove the replacement legacy import code](#1585) we could review the replacement 'import job' we created in a clearer light.

The immediate thing that rang out was that we are not importing a license! The job is connected to the import licence process, but specifically, it cares about changes to the licence. Hence the name change.

After that, we could see the job and the two downstream processes it kicks off from a bird's eye view.

What jumped out is they were both doing there own variation of the same thing: working out what the 'change date' is. Plus, in the case of return logs it was re-quering the DB for information that could be retrieved in the job's `FetchLicenceService`.

So, in this change we have refactored the job to handle both

- determining that a licence has a changed 'end date'
- determining what that changed date is

As the job has this information, it can then pass it to the downstream services, which means we can delete the redundant code from them.

Along the way, we do some housekeeping: updating the job to match the existing jobs, enhancing the comments, and fixing a whoopsie in the query `FetchLicencesServices` uses! 😱 😁
  • Loading branch information
Cruikshanks authored Jan 3, 2025
1 parent a16a9ad commit a236317
Show file tree
Hide file tree
Showing 25 changed files with 864 additions and 968 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ REDIS_DISABLE_TLS=false
BILLING_ANNUAL_BATCH_SIZE=5
BILLING_WAIT_FOR_STATUS_PAUSE_IN_MS=1000

# Jobs config
JOBS_LICENCE_CHANGES_BATCH_SIZE=10

# Cookie secret for authenticating requests coming via the UI. Note that the value should be the same as `COOKIE_SECRET`
# on the UI side
COOKIE_SECRET=
Expand Down
30 changes: 14 additions & 16 deletions app/controllers/check.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,42 @@ const ProcessLicenceReturnLogsService = require('../services/return-logs/process
const NO_CONTENT_STATUS_CODE = 204

/**
* A test end point for the licence supplementary billing flags process
* A test end point for checking licences with changed end dates on import are flagged for supplementary billing
*
* This endpoint takes a licenceId and an expired, lapsed and revoked date. It passes this onto the
* `DetermineSupplementaryBillingFlagsService` to test if it correctly flags the licence for supplementary billing. This
* normally happens during the licence import process.
* This endpoint takes a licenceId and 'changeDate'. It passes this onto the
* `ProcessBillingFlagService` to test if it correctly flags the licence for supplementary billing. This would normally
* be done as part of `/jobs/licence-changes`. But that checks all licences and is driven by comparing NALD and WRLS.
*
* This endpoint allows us to test a licence in isolation, with a 'change date' of our choosing.
*
* @param request - the hapi request object
* @param h - the hapi response object
*
* @returns {Promise<object>} - A promise that resolves to an HTTP response object with a 204 status code
*/
async function flagForBilling(request, h) {
const { licenceId, expiredDate, lapsedDate, revokedDate } = request.payload

const payload = {
expiredDate: expiredDate ? new Date(expiredDate) : null,
lapsedDate: lapsedDate ? new Date(lapsedDate) : null,
licenceId,
revokedDate: revokedDate ? new Date(revokedDate) : null
}
const { licenceId, changeDate } = request.payload

await ProcessBillingFlagService.go(payload)
await ProcessBillingFlagService.go({ licenceId, changeDate: new Date(changeDate) })

return h.response().code(NO_CONTENT_STATUS_CODE)
}

/**
* A test end point to create return logs for a given licence reference
* A test end point for checking we correctly reissue the return logs for a given licence
*
* We always expect a `licenceId` and an optional `changeDate` to be passed in the request. If a `changeDate` is not
* provided, the current date will be used.
*
* @param request - the hapi request object
* @param h - the hapi response object
*
* @returns {Promise<object>} - A promise that resolves to an HTTP response object with a 204 status code
*/
async function licenceReturnLogs(request, h) {
const { licenceId } = request.params
const { licenceId, changeDate } = request.payload

await ProcessLicenceReturnLogsService.go(licenceId)
await ProcessLicenceReturnLogsService.go(licenceId, changeDate ? new Date(changeDate) : null)

return h.response().code(NO_CONTENT_STATUS_CODE)
}
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/jobs.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

const ExportService = require('../services/jobs/export/export.service.js')
const ImportLicence = require('../services/jobs/import/import-licences.service.js')
const ProcessLicenceChanges = require('../services/jobs/licence-changes/process-licence-changes.service.js')
const ProcessLicenceUpdates = require('../services/jobs/licence-updates/process-licence-updates.js')
const ProcessReturnLogsService = require('../services/jobs/return-logs/process-return-logs.service.js')
const ProcessSessionStorageCleanupService = require('../services/jobs/session-cleanup/process-session-storage-cleanup.service.js')
Expand All @@ -30,8 +30,8 @@ async function exportDb(_request, h) {
return h.response().code(NO_CONTENT_STATUS_CODE)
}

async function ImportLicences(_request, h) {
ImportLicence.go()
async function licenceChanges(_request, h) {
ProcessLicenceChanges.go()

return h.response().code(NO_CONTENT_STATUS_CODE)
}
Expand Down Expand Up @@ -68,7 +68,7 @@ async function returnLogs(request, h) {

module.exports = {
exportDb,
ImportLicences,
licenceChanges,
licenceUpdates,
returnLogs,
sessionCleanup,
Expand Down
4 changes: 2 additions & 2 deletions app/routes/jobs.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const routes = [
},
{
method: 'POST',
path: '/jobs/import-licences',
path: '/jobs/licence-changes',
options: {
handler: JobsController.ImportLicences,
handler: JobsController.licenceChanges,
app: {
plainOutput: true
},
Expand Down

This file was deleted.

40 changes: 0 additions & 40 deletions app/services/jobs/import/fetch-licences.service.js

This file was deleted.

46 changes: 0 additions & 46 deletions app/services/jobs/import/generate-return-logs.service.js

This file was deleted.

44 changes: 0 additions & 44 deletions app/services/jobs/import/process-import-licence.service.js

This file was deleted.

Loading

0 comments on commit a236317

Please sign in to comment.