Skip to content

Commit

Permalink
Fix errors in nightly process & tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruikshanks committed Sep 17, 2024
1 parent c4d55ef commit bcccec4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
14 changes: 8 additions & 6 deletions src/modules/nightly-import/process-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ async function go () {
await _naldDataProcess(allResults)
await _cleanProcess(allResults)
await _permitProcess(allResults)
await _companyDetailsProcess.go(allResults)
await _licenceDetailsProcess.go(allResults)
await _modLogsProcess.go(allResults)
await _returnVersionsProcess.go(allResults)
await _companyDetailsProcess(allResults)
await _licenceDetailsProcess(allResults)
await _modLogsProcess(allResults)
await _returnVersionsProcess(allResults)

const logData = calculateAndLogTimeTaken(startTime, 'nightly-import complete')
const timeMessage = _timeMessage(logData.timeTakenSs)
const emailMessage = _message(allResults, timeMessage)

await TrackerProcessSteps.go(emailMessage)
} catch (error) {
console.log(error)
global.GlobalNotifier.oops('nightly-import failed')
}
}
Expand Down Expand Up @@ -76,7 +77,7 @@ function _allResults () {
completed: false
},
returnVersions: {
title: 'Mod logs process',
title: 'Return versions process',
description: 'Imports NALD return version data, then corrects known issues with it, ready for use in WRLS.',
attempted: false,
completed: false
Expand Down Expand Up @@ -188,7 +189,8 @@ async function _returnVersionsProcess (allResults) {
returnVersions.completed = await ReturnVersionsProcessSteps.go()
}

function _timeMessage (seconds) {
function _timeMessage (secondsAsBigInt) {
const seconds = Number(secondsAsBigInt)
const hours = Math.floor(seconds / 3600)
const minutes = Math.floor((seconds % 3600) / 60)
const remainingSeconds = seconds % 60
Expand Down
2 changes: 1 addition & 1 deletion src/modules/tracker/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const ProcessSteps = require('./process-steps.js')

async function tracker (_request, h) {
ProcessSteps.go()
ProcessSteps.go('Someone triggered a test of the tracker email. You can ignore this message (it obviously worked!)')

return h.response().code(204)
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/tracker/process-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const SendEmailStep = require('./steps/send-email.js')

const { calculateAndLogTimeTaken, currentTimeInNanoseconds } = require('../../lib/general.js')

async function go () {
async function go (message) {
let processComplete = false

try {
global.GlobalNotifier.omg('tracker started')

const startTime = currentTimeInNanoseconds()

await SendEmailStep.go()
await SendEmailStep.go(message)

processComplete = true

Expand Down
16 changes: 3 additions & 13 deletions src/modules/tracker/steps/send-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ const NotifyConnector = require('../../../lib/connectors/water/notify.js')

const config = require('../../../../config.js')

async function go (message = null) {
async function go (message) {
try {
global.GlobalNotifier.omg('tracker.send-email started')

const startTime = currentTimeInNanoseconds()

const content = _content(message)
const environment = `Sent from ${config.environment}\n\n`

_send(content)
_send(`${environment}${message}`)

calculateAndLogTimeTaken(startTime, 'tracker.send-email complete')
} catch (error) {
Expand All @@ -22,16 +22,6 @@ async function go (message = null) {
}
}

function _content (message) {
const environment = `Sent from ${config.environment}\n\n`

if (!message) {
return `${environment}Someone triggered a test of the tracker email. You can ignore this message (it worked!)`
}

return `${environment}${message}`
}

function _send (content) {
NotifyConnector.postSendNotify(
'email',
Expand Down

0 comments on commit bcccec4

Please sign in to comment.