Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganise into a single 'import process' spike #1023

Draft
wants to merge 51 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
4e735b9
Reorganise into a single 'import process' spike
Cruikshanks Sep 10, 2024
d6f931f
Add a new way to log an error msg without airbrake
Cruikshanks Sep 10, 2024
f4e9e56
Add query method to the DB object
Cruikshanks Sep 10, 2024
37515de
Add our calculate time loggers
Cruikshanks Sep 10, 2024
8f6f00d
Stop registering pg-boss based plugins
Cruikshanks Sep 10, 2024
8a71736
Add process version of nald download & extract
Cruikshanks Sep 10, 2024
94f35a0
Add new clean process
Cruikshanks Sep 10, 2024
f46e635
Add routes for our new processes to main routes
Cruikshanks Sep 10, 2024
bd0e79d
Working version permit and document header import
Cruikshanks Sep 11, 2024
7f66664
Drop dependence on repository
Cruikshanks Sep 11, 2024
dc2ff6f
Batch up the work
Cruikshanks Sep 11, 2024
b28fb59
Working version of the companies import
Cruikshanks Sep 12, 2024
2a23f82
Add the nightly import
Cruikshanks Sep 12, 2024
20eb296
Correct controller import naming
Cruikshanks Sep 12, 2024
a2fde21
Remove water import
Cruikshanks Sep 12, 2024
cbe8b92
Convert return versions from a job to a process
Cruikshanks Sep 12, 2024
79db199
Rename companies-import to crm
Cruikshanks Sep 12, 2024
dd21737
Rename permit-import to just permit
Cruikshanks Sep 12, 2024
099e8de
Convert mod-logs from job to a process
Cruikshanks Sep 12, 2024
7c37613
Housekeeping - flag param as unused
Cruikshanks Sep 12, 2024
8925341
Remove nald-import
Cruikshanks Sep 13, 2024
8840f91
Move all reference data imports to a single process
Cruikshanks Sep 13, 2024
e021088
Migrate charging-import to a process
Cruikshanks Sep 13, 2024
639459e
Remove delete document and company import jobs
Cruikshanks Sep 13, 2024
9837193
Remove the queue and import system job
Cruikshanks Sep 13, 2024
0ac9e61
Migrate bill runs import to be a process
Cruikshanks Sep 13, 2024
5887735
Move DateHelpers to lib
Cruikshanks Sep 16, 2024
425f9a1
Working version of the licence import job
Cruikshanks Sep 16, 2024
32e787e
Working version of licence import with error handling
Cruikshanks Sep 16, 2024
5cc4390
Reduce DB calls in water import
Cruikshanks Sep 16, 2024
1182461
Add points import step to water process
Cruikshanks Sep 16, 2024
e0cfcb8
Remove old licence-import jobs
Cruikshanks Sep 16, 2024
c27f4e6
Rename crm process to company-details
Cruikshanks Sep 16, 2024
1a56efa
Update company details to avoid 70K DB requests
Cruikshanks Sep 16, 2024
7b66faf
Update company details with allSettled and counts
Cruikshanks Sep 16, 2024
bb7a434
Update permit process with allSettled and counts
Cruikshanks Sep 16, 2024
8c48fa2
Rename water process licence-details
Cruikshanks Sep 16, 2024
cc3e048
Remove jobs endpoint
Cruikshanks Sep 16, 2024
5e327ea
Delete Application State modules
Cruikshanks Sep 16, 2024
7cfbc3e
Delete redundant document header delete modules
Cruikshanks Sep 16, 2024
ff8c957
Fix missed references to deleted modules
Cruikshanks Sep 16, 2024
ab495ad
Remove pgboss, node-cron & catbox-redis
Cruikshanks Sep 16, 2024
f5a211a
Migrate tracker job to process
Cruikshanks Sep 16, 2024
c4d55ef
Update nightly import to collate results
Cruikshanks Sep 17, 2024
bcccec4
Fix errors in nightly process & tracker
Cruikshanks Sep 17, 2024
ee65f26
ALways send an email and better handle process fail
Cruikshanks Sep 17, 2024
1a36924
Remove JWT authentication
Cruikshanks Sep 17, 2024
d2f9e0a
Remove redundant env vars from example
Cruikshanks Sep 17, 2024
5917c4b
Make batch sizes configurable
Cruikshanks Sep 17, 2024
78dda8f
Move permit process to last place in nightly
Cruikshanks Sep 17, 2024
1dd24e4
Ensure results align with process order
Cruikshanks Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
SERVICE_NAME=water-abstraction-import

JWT_TOKEN=
JWT_SECRET=

RETURNS_URI=
WATER_URI=
CRM_URI=
Expand All @@ -20,7 +17,6 @@ PROXY=
# Airbrake config
AIRBRAKE_HOST=https://my-errbit-instance.com
AIRBRAKE_KEY=longvaluefullofnumbersandlettersinlowercase
ENVIRONMENT=dev

ERRBIT_KEY=
ERRBIT_SERVER=
Expand All @@ -31,23 +27,17 @@ ENVIRONMENT=pre
IMPORT_RETURNS_YEARS=
NALD_ZIP_PASSWORD=

REDIS_URI=

S3_NALD_IMPORT_PATH=

WATER_SERVICE_MAILBOX=

# In processes like licence-details, configure how many 'things' to import within each batch
IMPORT_PROCESS_BATCH_SIZE=

# For development only! See https://eaflood.atlassian.net/browse/WATER-3201
# Enables import of licence agreements during the licence import process. This was a one time import
# run in production that we often need to re-run in local and non-production environments
IMPORT_LICENCE_AGREEMENTS=false

# Set log level for app. Default is 'info'
WRLS_LOG_LEVEL=debug

# Use Cron type syntax to set timings for these background processes
WRLS_CRON_NALD='0 1 * * *'
WRLS_CRON_LICENCES='0 4 * * 1,2,3,4,5'
WRLS_CRON_RETURN_VERSIONS='0 6 * * 1,2,3,4,5'
WRLS_CRON_MOD_LOGS='0 7 * * 1,2,3,4,5'
WRLS_CRON_TRACKER='0 10 * * 1,2,3,4,5'
WRLS_LOG_LEVEL=info
42 changes: 6 additions & 36 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@ require('dotenv').config()
const environment = process.env.ENVIRONMENT
const isProduction = environment === 'prd'

const isTlsConnection = (process.env.REDIS_HOST || '').includes('aws')

module.exports = {

blipp: {
showAuth: true
},

jwt: {
key: process.env.JWT_SECRET,
verifyOptions: { algorithms: ['HS256'] }
},

// This config is specifically for hapi-pino which was added to replace the deprecated (and noisy!) hapi/good. At
// some point all logging would go through this. But for now, it just covers requests & responses
log: {
Expand Down Expand Up @@ -48,12 +41,6 @@ module.exports = {
max: 20
},

pgBoss: {
schema: 'water_import',
application_name: process.env.SERVICE_NAME,
newJobCheckIntervalSeconds: 10
},

server: {
port: 8007,
router: {
Expand All @@ -80,14 +67,15 @@ module.exports = {

proxy: process.env.PROXY,

// In processes like licence-details, configure how many 'things' to import within each batch
processBatchSize: parseInt(process.env.IMPORT_PROCESS_BATCH_SIZE) || 10,

import: {
nald: {
zipPassword: process.env.NALD_ZIP_PASSWORD,
path: process.env.S3_NALD_IMPORT_PATH || 'wal_nald_data_release',
schedule: process.env.WRLS_CRON_NALD || '0 1 * * *'
path: process.env.S3_NALD_IMPORT_PATH || 'wal_nald_data_release'
},
licences: {
schedule: process.env.WRLS_CRON_LICENCES || '0 4 * * 1,2,3,4,5',
// Note: these 2 flags need to be set to false for charging go-live
// to suspend the import of invoice accounts and licence agreements
// Update: I've changed those values to false ahead of the v2.0 charging
Expand All @@ -102,28 +90,10 @@ module.exports = {
// This will supersede the implementation here where the billing contact history
// was calculated from NALD data
isBillingDocumentRoleImportEnabled: false
},
modLogs: {
schedule: process.env.WRLS_CRON_MOD_LOGS || '0 7 * * 1,2,3,4,5'
},
returnVersions: {
schedule: process.env.WRLS_CRON_RETURN_VERSIONS || '0 6 * * 1,2,3,4,5'
},
tracker: {
schedule: process.env.WRLS_CRON_TRACKER || '0 10 * * 1,2,3,4,5'
}
},

redis: {
host: process.env.REDIS_HOST || '127.0.0.1',
port: process.env.REDIS_PORT || 6379,
password: process.env.REDIS_PASSWORD || '',
...(isTlsConnection) && { tls: {} },
db: 0
},
notify: {
templates: {
service_status_alert: 'c34d1b16-694b-4364-8e7e-83e9dbd34a62'
}
mailbox: process.env.WATER_SERVICE_MAILBOX,
templateId: 'c34d1b16-694b-4364-8e7e-83e9dbd34a62'
}
}
23 changes: 1 addition & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ require('dotenv').config()
// -------------- Require vendor code -----------------
const Blipp = require('blipp')

const HapiAuthJwt2 = require('hapi-auth-jwt2')
const moment = require('moment')

moment.locale('en-gb')
Expand All @@ -23,26 +22,9 @@ const plugins = [
{
plugin: Blipp,
options: config.blipp
},
HapiAuthJwt2,
require('./src/plugins/pg-boss.plugin'),
require('./src/modules/licence-import/plugin'),
require('./src/modules/charging-import/plugin'),
require('./src/modules/mod-logs/plugin'),
require('./src/modules/return-versions/plugin.js'),
require('./src/modules/nald-import/plugin'),
require('./src/modules/bill-runs-import/plugin'),
require('./src/modules/core/plugin')
}
]

const configureServerAuthStrategy = (server) => {
server.auth.strategy('jwt', 'jwt', {
...config.jwt,
validate: async (decoded) => ({ isValid: !!decoded.id })
})
server.auth.default('jwt')
}

const start = async function () {
await server.register(plugins)

Expand All @@ -54,8 +36,6 @@ const start = async function () {

server.validator(require('@hapi/joi'))

configureServerAuthStrategy(server)

server.route(routes)

if (!module.parent) {
Expand Down Expand Up @@ -83,7 +63,6 @@ process
// If there are no in-flight requests Hapi will immediately stop. If there are they get 25 seconds to finish
// before Hapi terminates them
await server.stop(options)
await server.messageQueue.stop()

// Log we're shut down using the same log format as the rest of our log output
server.logger.info("That's all folks!")
Expand Down
Loading
Loading