Skip to content

Commit 19f629c

Browse files
Merge branch 'main' into chile
2 parents d6d17df + eb7bd7e commit 19f629c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+857
-295
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
./backend/data
2-
2+
.env
33

CHANGELOG.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,30 @@
99
- Integrate new, comparison-based frontend
1010
- Integrate backend for content-redaction
1111
- Old frontend: modularize
12+
- Dockerize whole architecture, provide redundancy
1213

1314
# [2.0.5]
15+
16+
## Features
17+
- Overall:
18+
- all components of architecture now dockerized
19+
- Compare frontend
20+
- link click on eqSelection with form
21+
- mirrorClick rule now allows `include` and `exclude` of `compositeId`s
22+
- styles feature differently on click
23+
- Custom converter for wizard/eqSim
24+
- exposure now displayed
1425
- Ongoing
15-
- link click on eqSelection with form
16-
- dropdown doesnt know which of the options the new value is
17-
- add a `valueToKey` property to wizardComplex?
18-
- new rule: focus on first step from beginning
1926
- Upcoming
2027
- create a docker-compose.yml for backend, frontends and monitor
21-
- create a global config-file
22-
- style layer differently on click
2328
- translation service
24-
- focus on eq-selection immediately
2529
- steps: show errors
2630
- auto-pilot: configurable start-strategy
2731

32+
## Bug fixes
33+
- Compare frontend
34+
- Map zooms in to first available step right after selecting a scenario
35+
2836
# [2.0.4](https://github.com/riesgos/dlr-riesgos-frontend/releases/tag/2.0.4) (May 16 2023) Created monitor and new frontend
2937
## Features
3038
- monitor:
@@ -34,15 +42,10 @@
3442
- tickets now stay alive for a certain time after they've been fetched
3543
- added `execute?skipCache=true` option for execute-requests
3644
- added `runall.ts` which runs all steps once every hour.
37-
- fix: logging threw error on circular objects.
3845
- added `expires` headers
3946
- frontend:
4047
- now allows multiple (dynamic) legends for one layer at the same time. Applied to eq-catalogue.
4148
- now has circle-legend
42-
- fix: race condition in making post-eq-damage mapable.
43-
- fix: wrong style and legend for chile-damage.
44-
- fix: *should* have fixed NS_BINDING_ABORTED.
45-
- fix: error in one process does not stop processing of other processes.
4649
- Compare frontend
4750
- all code now in modules
4851
- map allows per-step data-converters which are semi-automatically injected
@@ -68,9 +71,7 @@
6871
- insideOne ruleset: data now mirrored
6972
- auto-pilot only started when rules allow it
7073
- legends now displayed - if present
71-
- fix: layer- and wizard-services no longer cause multiple ui-updates on every state-change (reason: base-observable now shared)
7274
- popup: increased close button clickable area
73-
- fix: click on map only fires click-handler *once*.
7475
- dropdown now selects value when clicked on map
7576
- wizard expanded from beginning: did need to move `share` up in filter-obs
7677
- reducers: parseAPIScenariosIntoNewState: strict typing
@@ -79,9 +80,16 @@
7980
# [2.0.3](https://github.com/riesgos/dlr-riesgos-frontend/releases/tag/2.0.3) (Mar. 9 2023) Bug fixes
8081

8182
## Bug fixes
83+
- layer- and wizard-services no longer cause multiple ui-updates on every state-change (reason: base-observable now shared)
84+
- click on map only fires click-handler *once*.
8285
- removed superfluous console-logs
8386
- literal parameters of eq-catalog were not accepted
8487
- because no `userDataProvided` action triggered when user edits literal values
88+
- logging threw error on circular objects.
89+
- race condition in making post-eq-damage mapable.
90+
- wrong style and legend for chile-damage.
91+
- *should* have fixed NS_BINDING_ABORTED (happend in Firefox, presumably because too many posts at the same time).
92+
- error in one process does not stop processing of other processes.
8593

8694

8795

backend/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM node:16
2+
3+
WORKDIR backend
4+
5+
# install and build
6+
COPY . .
7+
RUN npm ci
8+
RUN npm run build:prod
9+
10+
# config
11+
ENV maxStoreLifeTimeMinutes "1440"
12+
# adminEmails: comma separated list
13+
ENV adminEmails ""
14+
ENV sourceEmail "info@test.com"
15+
ENV port "8008"
16+
17+
18+
# running
19+
EXPOSE ${port}
20+
CMD ["node", "dist/main.js"]

backend/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "scenarios",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"description": "",
55
"scripts": {
66
"build:prod": "tsc --build",
77
"build:watch": "tsc -w",
88
"start": "ts-node-dev --respawn src/main.ts",
9-
"test": "jest --runInBand",
10-
"test:watch": "jest --watch",
9+
"test": "jest --runInBand --bail",
10+
"test:watch": "jest --watch --bail",
1111
"run": "node dist/main.js"
1212
},
1313
"keywords": [

backend/src/config.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

backend/src/logging/logger.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function externalFunction() {
1919

2020
test("Logs are written to file", async () => {
2121

22-
const logger = new Logger(logDir)
22+
const logger = new Logger(logDir, [])
2323
logger.monkeyPatch();
2424

2525
externalFunction();

backend/src/logging/logger.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { appendFileSync } from "fs"
22
import { createFileSync, getFileAgeSync, renameFileSync } from "../utils/files";
33
import { MailClient } from "../web/mailClient";
4-
import { config } from '../config';
54
import { inspect } from 'util';
65

76

@@ -11,9 +10,10 @@ export class Logger {
1110

1211
constructor(
1312
private loggingDir: string,
13+
private sendMailTo: string[] = [],
14+
private sender: string = "info@test.com",
1415
private verbosity: 'verbose' | 'silent' = 'verbose',
15-
private maxLogAge = 24 * 60 * 60,
16-
private sendMailOnError = true
16+
private maxLogAgeMinutes = 24 * 60,
1717
) {
1818
this.loggingDir = loggingDir.replace(/\/+$/, '');
1919
}
@@ -53,7 +53,7 @@ export class Logger {
5353
const fullErrorString = time.toISOString() + "---" + messageString + "\n" + additionalText + "\n";
5454
appendFileSync(`${this.loggingDir}/errors.txt`, fullErrorString);
5555

56-
if (this.sendMailOnError) this.mailClient.sendMail([config.adminEmail], 'RIESGOS 2.0: an error has occured', fullErrorString);
56+
if (this.sendMailTo.length > 0) this.mailClient.sendMail(this.sender, this.sendMailTo, 'RIESGOS 2.0: an error has occured', fullErrorString);
5757
}
5858

5959
private messageToString(message: any) {
@@ -75,7 +75,7 @@ export class Logger {
7575
if (fileAgeSecs === -1) {
7676
createFileSync(filePath);
7777
}
78-
if (fileAgeSecs > this.maxLogAge) {
78+
if (fileAgeSecs > this.maxLogAgeMinutes * 60) {
7979
renameFileSync(filePath, `${filePath}_${new Date().toISOString()}.txt`);
8080
createFileSync(filePath);
8181
}

backend/src/main.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
import { config } from './config';
21
import cors from 'cors';
32
import express from 'express';
4-
import { addScenarioApi } from './scenarios/scenario.interface';
3+
import { ScenarioAPIConfig, addScenarioApi } from './scenarios/scenario.interface';
54
// import { parseCode } from './parser/scenarioParser';
65
import { peruFactory } from './usr/peru/peru';
76
import { peruShortFactory } from './usr/peru_short/peru';
87
import { chileFactory } from './usr/chile/chile';
98
import { ecuadorFactory } from './usr/ecuador/ecuador';
109

1110

12-
const port = config.port;
11+
const port = parseInt(process.env.port || "8008");
1312
const logDir = `./data/logs/`; // server-logs
1413
const storeDir = `./data/store/`; // files that must be available to outside
1514
const scriptDir = './data/scenarios'; // user-defined logic
1615

1716

17+
const config: ScenarioAPIConfig = {
18+
logDir: logDir,
19+
maxStoreLifeTimeMinutes: parseInt(process.env.maxStoreLifetimeMinutes || "60"),
20+
sender: process.env.sourceEmail || "info@test.com",
21+
sendMailTo: (process.env.adminEmails || "").split(","),
22+
maxLogAgeMinutes: 24 * 60,
23+
storeDir: storeDir,
24+
verbosity: 'verbose'
25+
}
1826

1927
async function main() {
2028
const app = express();
@@ -23,7 +31,7 @@ async function main() {
2331
// const scenarioFactories = await parseCode(scriptDir);
2432
const scenarioFactories = [chileFactory, ecuadorFactory, peruFactory, peruShortFactory];
2533

26-
addScenarioApi(app, scenarioFactories, storeDir, logDir, 'verbose', true);
34+
addScenarioApi(app, scenarioFactories, config);
2735
const server = app.listen(port, () => console.log(`app now listening on port ${port}`));
2836
}
2937

backend/src/scenarios/scenario.interface.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ import { ProcessPool } from './pool';
44
import { DatumLinage, Scenario, ScenarioFactory, ScenarioState } from './scenarios';
55
import { Logger } from '../logging/logger';
66
import { FileStorage } from '../storage/fileStorage';
7-
import { config } from '../config';
87

98

10-
export function addScenarioApi(app: Express, scenarioFactories: ScenarioFactory[], storeDir: string, loggingDir: string, verbosity: 'verbose' | 'silent' = 'verbose', sendMailOnError = true) {
9+
export interface ScenarioAPIConfig {
10+
sendMailTo: string[];
11+
sender: string;
12+
maxLogAgeMinutes: number | undefined;
13+
storeDir: string;
14+
logDir: string;
15+
verbosity: 'verbose' | 'silent';
16+
maxStoreLifeTimeMinutes: number;
17+
}
18+
19+
export function addScenarioApi(app: Express, scenarioFactories: ScenarioFactory[], config: ScenarioAPIConfig) {
1120
app.use(express.json({
1221
limit: '50mb' // required because exposure objects can become pretty big
1322
}));
@@ -17,9 +26,9 @@ export function addScenarioApi(app: Express, scenarioFactories: ScenarioFactory[
1726
});
1827

1928
const pool = new ProcessPool();
20-
const fs = new FileStorage<DatumLinage>(storeDir, config.maxStoreLifeTimeMinutes * 60);
29+
const fs = new FileStorage<DatumLinage>(config.storeDir, config.maxStoreLifeTimeMinutes);
2130
const scenarios = scenarioFactories.map(sf => sf.createScenario(fs));
22-
const logger = new Logger(loggingDir, verbosity, undefined, sendMailOnError);
31+
const logger = new Logger(config.logDir, config.sendMailTo, config.sender, config.verbosity, config.maxLogAgeMinutes);
2332
logger.monkeyPatch();
2433

2534

@@ -60,6 +69,10 @@ export function addScenarioApi(app: Express, scenarioFactories: ScenarioFactory[
6069
app.get('/files/:hash', async (req, res) => {
6170
const hash = req.params.hash;
6271
const cachedData = await fs.getDataByKey(hash);
72+
if (!cachedData) {
73+
console.error(`No such file: ${hash}`);
74+
res.statusCode = 404;
75+
}
6376
res.send(cachedData);
6477
});
6578

backend/src/scenarios/scenarios.errors.test.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios from 'axios';
22
import { Server } from 'http';
33
import express, { Express } from 'express';
4-
import { addScenarioApi } from './scenario.interface';
4+
import { ScenarioAPIConfig, addScenarioApi } from './scenario.interface';
55
import { Datum, ScenarioFactory, ScenarioState } from './scenarios';
66
import { sleep } from '../utils/async';
77
import { deleteFile } from '../utils/files';
@@ -64,22 +64,31 @@ fakeScenarioFactory.registerStep({
6464
const sendMailOnError = false;
6565
const http = axios.create();
6666
const port = 5003;
67-
const logDir = './test-data/scenario-errors/logs';
68-
const storeDir = './test-data/scenario-errors/store';
67+
const config: ScenarioAPIConfig = {
68+
logDir: './test-data/scenario-errors/logs',
69+
storeDir: './test-data/scenario-errors/store',
70+
verbosity: 'silent',
71+
sendMailTo: [],
72+
sender: "",
73+
maxLogAgeMinutes: 60,
74+
maxStoreLifeTimeMinutes: 60
75+
}
76+
77+
6978
let app: Express;
7079
let server: Server;
7180
beforeAll(async () => {
72-
await deleteFile(storeDir);
73-
await deleteFile(logDir);
81+
await deleteFile(config.storeDir);
82+
await deleteFile(config.logDir);
7483
app = express();
7584
app.use(express.json());
7685
const scenarioFactories = [fakeScenarioFactory];
77-
addScenarioApi(app, scenarioFactories, storeDir, logDir, 'silent', sendMailOnError);
86+
addScenarioApi(app, scenarioFactories, config);
7887
server = app.listen(port, () => {});
7988
});
8089

8190
afterAll(async () => {
82-
await deleteFile(storeDir);
91+
await deleteFile(config.storeDir);
8392
server.close();
8493
});
8594

0 commit comments

Comments
 (0)