-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing information to
/health/info
page (#376)
https://eaflood.atlassian.net/browse/WATER-4099 Finish off the work previously started on the `/health/info` page. The data that is missing that needs to be added in this PR is: - Confirm Redis is running - Display the latest results for the import app The changes to add the Redis info have been moved into a separate PR #402 so that this PR is just focusing on the import information.
- Loading branch information
Showing
4 changed files
with
304 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
'use strict' | ||
|
||
/** | ||
* Fetches details of the pg-boss jobs run by the Import service in the last 24hrs | ||
* @module FetchImportJobs | ||
*/ | ||
|
||
const { db } = require('../../../db/db.js') | ||
|
||
/** | ||
* Returns data required to populate the Import tasks of our `/health/info` page. | ||
*/ | ||
async function go () { | ||
const PGBOSS_JOBS_ARRAY = [ | ||
'import.bill-runs', | ||
'import.charge-versions', | ||
'import.charging-data', | ||
'import.tracker', | ||
'licence-import.delete-removed-documents', | ||
'licence-import.import-company', | ||
'licence-import.import-licence', | ||
'licence-import.import-purpose-condition-types', | ||
'licence-import.queue-companies', | ||
'licence-import.queue-licences', | ||
'nald-import.delete-removed-documents', | ||
'nald-import.import-licence', | ||
'nald-import.queue-licences', | ||
'nald-import.s3-download' | ||
] | ||
const currentDateMinusOneDay = _subtractDaysFromCurrentDate(1) | ||
|
||
return db | ||
.select('name') | ||
.count({ completedCount: db.raw("CASE WHEN state = 'completed' THEN 1 END") }) | ||
.count({ failedCount: db.raw("CASE WHEN state = 'failed' THEN 1 END") }) | ||
.count({ activeCount: db.raw("CASE WHEN state IN ('active', 'created') THEN 1 END") }) | ||
.max('completedon as maxCompletedonDate') | ||
.from( | ||
(db | ||
.select( | ||
'name', | ||
'state', | ||
'completedon' | ||
) | ||
.from('water_import.job') | ||
.whereIn('state', ['failed', 'completed', 'active', 'created']) | ||
.whereIn('name', PGBOSS_JOBS_ARRAY) | ||
.where((builder) => | ||
builder | ||
.where('createdon', '>', currentDateMinusOneDay) | ||
.orWhere('completedon', '>', currentDateMinusOneDay) | ||
) | ||
.unionAll( | ||
db | ||
.select( | ||
'name', | ||
'state', | ||
'completedon' | ||
) | ||
.from('water_import.archive') | ||
.whereIn('state', ['failed', 'completed', 'active', 'created']) | ||
.whereIn('name', PGBOSS_JOBS_ARRAY) | ||
.where((builder) => | ||
builder | ||
.where('createdon', '>', currentDateMinusOneDay) | ||
.orWhere('completedon', '>', currentDateMinusOneDay) | ||
) | ||
)) | ||
.as('jobs') | ||
) | ||
.groupBy('name') | ||
} | ||
|
||
/** | ||
* Calculates the current date minus the number of days passed to it | ||
* | ||
* @param {Number} days The number of days to be deducted from the currect date | ||
* | ||
* @returns {Date} The current date minus the number days passed to the function | ||
*/ | ||
function _subtractDaysFromCurrentDate (days) { | ||
const date = new Date() | ||
date.setDate(date.getDate() - days) | ||
|
||
return date | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.