Skip to content

Commit 1a5422a

Browse files
authored
Merge pull request #315 from bcgov/bug/large-sync-jobs
Improved handling of large sync jobs
2 parents 77991bb + 6c1bc76 commit 1a5422a

File tree

15 files changed

+130
-38
lines changed

15 files changed

+130
-38
lines changed

.github/environments/values.dev.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ features:
55
oidcAuth: true
66

77
autoscaling:
8-
enabled: false
8+
enabled: true
99
pdb:
10-
enabled: false
10+
enabled: true
1111

1212
config:
1313
enabled: true

.github/environments/values.pr.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ features:
33
basicAuth: true
44
oidcAuth: true
55
defaultBucket: false
6+
7+
autoscaling:
8+
enabled: true
9+
pdb:
10+
enabled: true
611
#
712
#
813
# We don't deploy a postgrescluster for PR's

.github/environments/values.prod.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ postgres:
4848
requests:
4949
cpu: 256m
5050
memory: 512Mi
51-
limits:
52-
cpu: 512m
53-
memory: 1024Mi
5451
sidecars:
5552
replicaCertCopy:
5653
resources:

.github/environments/values.test.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ postgres:
4949
requests:
5050
cpu: 256m
5151
memory: 512Mi
52-
limits:
53-
cpu: 512m
54-
memory: 1024Mi
5552
sidecars:
5653
replicaCertCopy:
5754
resources:

app/README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ The following variables enable and enforce the use of Basic Authentication for r
4848

4949
The following variables configure the use of a backend database to support user-based access control, tagging and other advanced features
5050

51-
| Config Var | Env Var | Default | Notes |
52-
| ---------- | ------------- | --------- | --------------------------- |
53-
| `database` | `DB_DATABASE` | coms | COMS database name |
54-
| `host` | `DB_HOST` | localhost | Database conection hostname |
55-
| `username` | `DB_USERNAME` | app | Database account username |
56-
| `password` | `DB_PASSWORD` | | Database account password |
57-
| `port` | `DB_PORT` | 5432 | Database connection port |
58-
| `poolMin` | `DB_POOL_MIN` | 2 | avalable connections |
59-
| `poolMax` | `DB_POOL_MAX` | 10 | available connections |
51+
| Config Var | Env Var | Default | Notes |
52+
|----------------------------|---------------------------------|-----------|---------------------------------------------------------------------|
53+
| `acquireConnectionTimeout` | `DB_ACQUIRE_CONNECTION_TIMEOUT` | 90000 | Timeout length on acquiring a database connection (in milliseconds) |
54+
| `database` | `DB_DATABASE` | coms | COMS database name |
55+
| `host` | `DB_HOST` | localhost | Database conection hostname |
56+
| `username` | `DB_USERNAME` | app | Database account username |
57+
| `password` | `DB_PASSWORD` | | Database account password |
58+
| `port` | `DB_PORT` | 5432 | Database connection port |
59+
| `poolMin` | `DB_POOL_MIN` | 2 | avalable connections |
60+
| `poolMax` | `DB_POOL_MAX` | 10 | available connections |
61+
6062

6163
### Keycloak Variables
6264

app/config/custom-environment-variables.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"username": "BASICAUTH_USERNAME"
77
},
88
"db": {
9+
"acquireConnectionTimeout": "DB_ACQUIRE_CONNECTION_TIMEOUT",
910
"database": "DB_DATABASE",
1011
"host": "DB_HOST",
1112
"password": "DB_PASSWORD",

app/config/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"db": {
3+
"acquireConnectionTimeout": 90000,
34
"database": "coms",
45
"host": "localhost",
56
"port": "5432",

app/knexfile.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const config = require('config');
2+
const os = require('os');
23
const { format } = require('date-fns');
34

45
const log = require('./src/components/log')(module.filename);
@@ -31,13 +32,15 @@ types.setTypeParser(1184, (value) => new Date(value).toISOString());
3132
const logWrapper = (level, msg) => log.log(level, msg);
3233

3334
module.exports = {
35+
acquireConnectionTimeout: config.get('db.acquireConnectionTimeout'),
3436
client: 'pg',
3537
connection: {
3638
host: config.get('db.host'),
3739
user: config.get('db.username'),
3840
password: config.get('db.password'),
3941
database: config.get('db.database'),
40-
port: config.get('db.port')
42+
port: config.get('db.port'),
43+
application_name: os.hostname()
4144
},
4245
debug: ['silly', 'debug'].includes(config.get('server.logLevel')),
4346
log: {

app/src/components/queueManager.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ class QueueManager {
5757
checkQueue() {
5858
if (!this.isBusy && !this.toClose) {
5959
objectQueueService.queueSize().then(size => {
60-
if (size > 0) this.processNextJob();
60+
if (size > 0) {
61+
log.verbose(`There are ${size} jobs in the queue to process`, { function: 'checkQueue' });
62+
this.processNextJob();
63+
}
6164
}).catch((err) => {
6265
log.error(`Error encountered while checking queue: ${err.message}`, { function: 'checkQueue', error: err });
6366
});
@@ -93,7 +96,7 @@ class QueueManager {
9396
this.isBusy = true;
9497
job = response[0];
9598

96-
log.verbose(`Started processing job id ${job.id}`, { function: 'processNextJob', job: job });
99+
log.info(`Started processing job id ${job.id}`, { function: 'processNextJob', job: job });
97100

98101
const objectId = await syncService.syncJob(job.path, job.bucketId, job.full, job.createdBy);
99102

app/src/components/utils.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,15 @@ const utils = {
115115
return data;
116116
} catch (err) {
117117
log.error(err.message, { function: 'getBucket' });
118-
throw new Problem(404, { detail: err.message });
118+
if (err.name === 'NotFoundError') {
119+
throw new Problem(404, { detail: `bucketId ${bucketId} not found` });
120+
}
121+
else if (err.name == 'KnexTimeoutError') {
122+
throw new Problem(504, { detail: 'Database timeout' });
123+
}
124+
else {
125+
throw new Problem(500, { detail: err.message });
126+
}
119127
}
120128
},
121129

0 commit comments

Comments
 (0)