From 9811746a7477d1dc77e79474ef5b351556bed05d Mon Sep 17 00:00:00 2001 From: Alan Cruikshanks Date: Tue, 17 Sep 2024 20:42:17 +0100 Subject: [PATCH] Remove system jobs from licence-import https://eaflood.atlassian.net/browse/WATER-4670 We've been making changes to the import service to support our work migrating return version management to WRLS, and replacing the current licence import with [one ready for ReSP](https://eaflood.atlassian.net/browse/WATER-4535). We've also attempted to clarify what is actually happening during the various 'jobs' and to arrange them in our environments in a more logical order. But the latest version that shipped is failing to complete. We believe the issues are: - Each 'job' is taking longer to complete than expected - Based on current timings, the 'jobs' are overlapping - Our attempts to connect the new ReSP import with the existing one are adding to the burden - Based on investigating the logs, we think downstream jobs are no longer being triggered We're [working on simplifying the project](https://github.com/DEFRA/water-abstraction-import/pull/1023) and removing those elements we think decrease performance, for example, the use of [pg-boss](https://github.com/timgit/pg-boss). But in the meantime we need to get the import back up and running. This change removes the extra jobs we put in for connecting to the [water-abstraction-system](https://github.com/DEFRA/water-abstraction-system) till we can come up with a better alternative. We also update the default schedule to allow each part of the import more time to complete to avoid overlapping. --- .../jobs/import-licence-system.js | 60 ------------------- .../jobs/queue-licences-system.js | 53 ---------------- 2 files changed, 113 deletions(-) delete mode 100644 src/modules/licence-import/jobs/import-licence-system.js delete mode 100644 src/modules/licence-import/jobs/queue-licences-system.js diff --git a/src/modules/licence-import/jobs/import-licence-system.js b/src/modules/licence-import/jobs/import-licence-system.js deleted file mode 100644 index 821a3fa3..00000000 --- a/src/modules/licence-import/jobs/import-licence-system.js +++ /dev/null @@ -1,60 +0,0 @@ -'use strict' - -const WaterSystemService = require('../../../lib/services/water-system-service.js') -const QueueLicencesJob = require('./queue-licences.js') - -const JOB_NAME = 'licence-import.import-licence-system' -const STATUS_NO_CONTENT = 204 - -const options = { - teamSize: 75, teamConcurrency: 1 -} - -function createMessage (data) { - return { - name: JOB_NAME, - data, - options: { - singletonKey: `${JOB_NAME}.${data.licenceNumber}` - } - } -} - -async function handler (job) { - try { - if (job.data.jobNumber === 1) { - global.GlobalNotifier.omg(`${JOB_NAME}: started`) - } - - const { licenceNumber } = job.data - - const response = await WaterSystemService.postImportLicence({ - licenceRef: licenceNumber - }) - - if (response.statusCode !== STATUS_NO_CONTENT) { - throw new Error(`Licence ${licenceNumber} failed with status code - ${response.statusCode}`) - } - } catch (error) { - global.GlobalNotifier.omfg(`${JOB_NAME}: errored`, error) - throw error - } -} - -async function onComplete (messageQueue, job) { - try { - const { data } = job.data.request - - if (data.jobNumber === data.numberOfJobs) { - await messageQueue.publish(QueueLicencesJob.createMessage()) - global.GlobalNotifier.omg(`${JOB_NAME}: finished`, { numberOfJobs: job.data.request.data.numberOfJobs }) - } - } catch (error) { - global.GlobalNotifier.omfg(`${JOB_NAME}: errored`, error) - throw error - } -} - -module.exports = { - createMessage, handler, name: JOB_NAME, options, onComplete -} diff --git a/src/modules/licence-import/jobs/queue-licences-system.js b/src/modules/licence-import/jobs/queue-licences-system.js deleted file mode 100644 index cfca07fd..00000000 --- a/src/modules/licence-import/jobs/queue-licences-system.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict' - -const extract = require('../extract') -const ImportLicenceSystemJob = require('./import-licence-system.js') - -const JOB_NAME = 'licence-import.queue-licences-system' - -function createMessage () { - return { - name: JOB_NAME, - options: { - singletonKey: JOB_NAME, expireIn: '1 hours' - } - } -} - -async function handler () { - try { - global.GlobalNotifier.omg(`${JOB_NAME}: started`) - - const rows = await extract.getAllLicenceNumbers() - - return rows - } catch (error) { - global.GlobalNotifier.omfg(`${JOB_NAME}: errored`, error) - throw error - } -} - -async function onComplete (messageQueue, job) { - if (!job.failed) { - const { value: licences } = job.data.response - const numberOfJobs = licences.length - - for (const [index, licence] of licences.entries()) { - // This information is to help us log when the import licence jobs start and finish. See - // src/modules/licence-import/jobs/import-licence.js for more details - const data = { - licenceNumber: licence.LIC_NO, - jobNumber: index + 1, - numberOfJobs - } - - await messageQueue.publish(ImportLicenceSystemJob.createMessage(data)) - } - } - - global.GlobalNotifier.omg(`${JOB_NAME}: finished`) -} - -module.exports = { - createMessage, handler, onComplete, name: JOB_NAME -}