@golemio/rush-hour-aggregation 1.5.1 → 1.5.2-dev.2941756587
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/db/migrations/postgresql/20261004194210-snapshots-latest-index-usage.js +53 -0
- package/db/migrations/postgresql/sqls/20261004194210-snapshots-latest-index-usage-down.sql +203 -0
- package/db/migrations/postgresql/sqls/20261004194210-snapshots-latest-index-usage-up.sql +203 -0
- package/dist/integration-engine/WorkerHelper.d.ts +0 -3
- package/dist/integration-engine/WorkerHelper.js +0 -27
- package/dist/integration-engine/WorkerHelper.js.map +1 -1
- package/dist/integration-engine/constants.d.ts +1 -0
- package/dist/integration-engine/constants.js +5 -0
- package/dist/integration-engine/constants.js.map +1 -0
- package/dist/integration-engine/dataAccess/AbstractEventsRepository.d.ts +7 -0
- package/dist/integration-engine/dataAccess/AbstractEventsRepository.js +11 -8
- package/dist/integration-engine/dataAccess/AbstractEventsRepository.js.map +1 -1
- package/dist/integration-engine/dataAccess/AggregationRepository.d.ts +5 -4
- package/dist/integration-engine/dataAccess/AggregationRepository.js +25 -12
- package/dist/integration-engine/dataAccess/AggregationRepository.js.map +1 -1
- package/dist/integration-engine/dataAccess/DataRetentionRepository.d.ts +2 -1
- package/dist/integration-engine/dataAccess/DataRetentionRepository.js +22 -2
- package/dist/integration-engine/dataAccess/DataRetentionRepository.js.map +1 -1
- package/dist/integration-engine/dataAccess/FcdEventsRepository.d.ts +3 -1
- package/dist/integration-engine/dataAccess/FcdEventsRepository.js +2 -2
- package/dist/integration-engine/dataAccess/FcdEventsRepository.js.map +1 -1
- package/dist/integration-engine/dataAccess/NdicEventRepository.d.ts +3 -1
- package/dist/integration-engine/dataAccess/NdicEventRepository.js +2 -2
- package/dist/integration-engine/dataAccess/NdicEventRepository.js.map +1 -1
- package/dist/integration-engine/dataAccess/TskEventsRepository.d.ts +3 -1
- package/dist/integration-engine/dataAccess/TskEventsRepository.js +2 -2
- package/dist/integration-engine/dataAccess/TskEventsRepository.js.map +1 -1
- package/dist/integration-engine/dataAccess/WazeJamsRepository.d.ts +3 -1
- package/dist/integration-engine/dataAccess/WazeJamsRepository.js +2 -2
- package/dist/integration-engine/dataAccess/WazeJamsRepository.js.map +1 -1
- package/dist/integration-engine/dataAccess/WazeReconstructionsRepository.d.ts +3 -1
- package/dist/integration-engine/dataAccess/WazeReconstructionsRepository.js +2 -2
- package/dist/integration-engine/dataAccess/WazeReconstructionsRepository.js.map +1 -1
- package/dist/integration-engine/dataAccess/interfaces/IAggregationRepository.d.ts +5 -0
- package/dist/integration-engine/dataAccess/interfaces/IAggregationRepository.js +3 -0
- package/dist/integration-engine/dataAccess/interfaces/IAggregationRepository.js.map +1 -0
- package/dist/integration-engine/dataAccess/interfaces/IDataRetentionRepository.d.ts +3 -0
- package/dist/integration-engine/dataAccess/interfaces/IDataRetentionRepository.js +3 -0
- package/dist/integration-engine/dataAccess/interfaces/IDataRetentionRepository.js.map +1 -0
- package/dist/integration-engine/index.d.ts +2 -2
- package/dist/integration-engine/index.js +3 -17
- package/dist/integration-engine/index.js.map +1 -1
- package/dist/integration-engine/ioc/Di.d.ts +3 -0
- package/dist/integration-engine/ioc/Di.js +20 -0
- package/dist/integration-engine/ioc/Di.js.map +1 -0
- package/dist/integration-engine/ioc/RushHourAggregationContainerToken.d.ts +8 -0
- package/dist/integration-engine/ioc/RushHourAggregationContainerToken.js +12 -0
- package/dist/integration-engine/ioc/RushHourAggregationContainerToken.js.map +1 -0
- package/dist/integration-engine/service/AggregationFactory.d.ts +6 -2
- package/dist/integration-engine/service/AggregationFactory.js +32 -8
- package/dist/integration-engine/service/AggregationFactory.js.map +1 -1
- package/dist/integration-engine/service/aggregators/AbstractAggregator.d.ts +5 -0
- package/dist/integration-engine/service/aggregators/AbstractAggregator.js +6 -3
- package/dist/integration-engine/service/aggregators/AbstractAggregator.js.map +1 -1
- package/dist/integration-engine/service/aggregators/FcdEventsAggregator.d.ts +4 -1
- package/dist/integration-engine/service/aggregators/FcdEventsAggregator.js +4 -5
- package/dist/integration-engine/service/aggregators/FcdEventsAggregator.js.map +1 -1
- package/dist/integration-engine/service/aggregators/NdicEventsAggregator.d.ts +4 -1
- package/dist/integration-engine/service/aggregators/NdicEventsAggregator.js +4 -5
- package/dist/integration-engine/service/aggregators/NdicEventsAggregator.js.map +1 -1
- package/dist/integration-engine/service/aggregators/TskEventsAggregator.d.ts +4 -1
- package/dist/integration-engine/service/aggregators/TskEventsAggregator.js +4 -5
- package/dist/integration-engine/service/aggregators/TskEventsAggregator.js.map +1 -1
- package/dist/integration-engine/service/aggregators/WazeJamsAggregator.d.ts +4 -1
- package/dist/integration-engine/service/aggregators/WazeJamsAggregator.js +4 -5
- package/dist/integration-engine/service/aggregators/WazeJamsAggregator.js.map +1 -1
- package/dist/integration-engine/service/aggregators/WazeReconstructionsAggregator.d.ts +4 -1
- package/dist/integration-engine/service/aggregators/WazeReconstructionsAggregator.js +7 -5
- package/dist/integration-engine/service/aggregators/WazeReconstructionsAggregator.js.map +1 -1
- package/dist/integration-engine/service/interfaces/IAggregationFactory.d.ts +5 -0
- package/dist/integration-engine/service/interfaces/IAggregationFactory.js +3 -0
- package/dist/integration-engine/service/interfaces/IAggregationFactory.js.map +1 -0
- package/dist/integration-engine/workers/RushHourAggregationWorker.d.ts +7 -0
- package/dist/integration-engine/workers/RushHourAggregationWorker.js +21 -0
- package/dist/integration-engine/workers/RushHourAggregationWorker.js.map +1 -0
- package/dist/integration-engine/workers/interfaces/IAggregateDataTaskInput.d.ts +8 -0
- package/dist/integration-engine/workers/interfaces/IAggregateDataTaskInput.js +3 -0
- package/dist/integration-engine/workers/interfaces/IAggregateDataTaskInput.js.map +1 -0
- package/dist/integration-engine/workers/schema/AggregateDataTaskInputSchema.d.ts +9 -0
- package/dist/integration-engine/workers/schema/AggregateDataTaskInputSchema.js +49 -0
- package/dist/integration-engine/workers/schema/AggregateDataTaskInputSchema.js.map +1 -0
- package/dist/integration-engine/workers/task/AggregateDataTask.d.ts +24 -0
- package/dist/integration-engine/workers/task/AggregateDataTask.js +118 -0
- package/dist/integration-engine/workers/task/AggregateDataTask.js.map +1 -0
- package/dist/integration-engine/workers/task/RefreshHistoricViewsTask.d.ts +11 -0
- package/dist/integration-engine/workers/task/RefreshHistoricViewsTask.js +58 -0
- package/dist/integration-engine/workers/task/RefreshHistoricViewsTask.js.map +1 -0
- package/docs/asyncapi.yaml +1 -1
- package/docs/implementation_documentation.md +17 -11
- package/package.json +1 -1
- package/templates/sqlQueries/NdicEventsFull.sql +3 -0
- package/dist/integration-engine/AggregationWorker.d.ts +0 -18
- package/dist/integration-engine/AggregationWorker.js +0 -88
- package/dist/integration-engine/AggregationWorker.js.map +0 -1
- package/dist/integration-engine/queueDefinitions.d.ts +0 -3
- package/dist/integration-engine/queueDefinitions.js +0 -36
- package/dist/integration-engine/queueDefinitions.js.map +0 -1
- package/docs/keeping_a_changelog.md +0 -48
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.RefreshHistoricViewsTask = void 0;
|
|
16
|
+
const constants_1 = require("../../constants");
|
|
17
|
+
const RushHourAggregationContainerToken_1 = require("../../ioc/RushHourAggregationContainerToken");
|
|
18
|
+
const AggregationTaskType_1 = require("../../../schema-definitions/helpers/AggregationTaskType");
|
|
19
|
+
const AbstractEmptyTask_1 = require("@golemio/core/dist/integration-engine/workers/AbstractEmptyTask");
|
|
20
|
+
const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
|
|
21
|
+
const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
|
|
22
|
+
let RefreshHistoricViewsTask = class RefreshHistoricViewsTask extends AbstractEmptyTask_1.AbstractEmptyTask {
|
|
23
|
+
constructor(dataRetentionRepository, aggregationFactory) {
|
|
24
|
+
super(constants_1.RUSH_HOUR_AGGREGATION_WORKER_NAME);
|
|
25
|
+
this.dataRetentionRepository = dataRetentionRepository;
|
|
26
|
+
this.aggregationFactory = aggregationFactory;
|
|
27
|
+
this.queueName = "refreshHistoricViews";
|
|
28
|
+
this.queueTtl = 23 * 60 * 60 * 1000;
|
|
29
|
+
}
|
|
30
|
+
async execute() {
|
|
31
|
+
const failures = [];
|
|
32
|
+
try {
|
|
33
|
+
await this.dataRetentionRepository.deleteOldData();
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
failures.push(`data retention (${err instanceof Error ? err.message : err})`);
|
|
37
|
+
}
|
|
38
|
+
for (const type of Object.values(AggregationTaskType_1.AggregationTaskType)) {
|
|
39
|
+
try {
|
|
40
|
+
await this.aggregationFactory.get(type).refreshHistoricMaterialView();
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
failures.push(`${type} (${err instanceof Error ? err.message : err})`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (failures.length > 0) {
|
|
47
|
+
throw new golemio_errors_1.GeneralError(`Unable to refresh historic views: ${failures.join(", ")}`, this.constructor.name);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.RefreshHistoricViewsTask = RefreshHistoricViewsTask;
|
|
52
|
+
exports.RefreshHistoricViewsTask = RefreshHistoricViewsTask = __decorate([
|
|
53
|
+
(0, tsyringe_1.injectable)(),
|
|
54
|
+
__param(0, (0, tsyringe_1.inject)(RushHourAggregationContainerToken_1.RushHourAggregationContainerToken.DataRetentionRepository)),
|
|
55
|
+
__param(1, (0, tsyringe_1.inject)(RushHourAggregationContainerToken_1.RushHourAggregationContainerToken.AggregationFactory)),
|
|
56
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
57
|
+
], RefreshHistoricViewsTask);
|
|
58
|
+
//# sourceMappingURL=RefreshHistoricViewsTask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RefreshHistoricViewsTask.js","sourceRoot":"","sources":["../../../../src/integration-engine/workers/task/RefreshHistoricViewsTask.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAkE;AAElE,mGAA8F;AAE9F,iGAAuE;AACvE,uGAAoG;AACpG,6EAAwE;AACxE,iEAAwE;AAGjE,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,qCAAiB;IAI3D,YAEI,uBAAyD,EACK,kBAA+C;QAE7G,KAAK,CAAC,6CAAiC,CAAC,CAAC;QAHjC,4BAAuB,GAAvB,uBAAuB,CAA0B;QACa,uBAAkB,GAAlB,kBAAkB,CAAqB;QAN1G,cAAS,GAAG,sBAAsB,CAAC;QACnC,aAAQ,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAQtC,CAAC;IAEM,KAAK,CAAC,OAAO;QAChB,MAAM,QAAQ,GAAa,EAAE,CAAC;QAE9B,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,uBAAuB,CAAC,aAAa,EAAE,CAAC;QACvD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,QAAQ,CAAC,IAAI,CAAC,mBAAmB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QAClF,CAAC;QAED,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,yCAAmB,CAAC,EAAE,CAAC;YACpD,IAAI,CAAC;gBACD,MAAM,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,2BAA2B,EAAE,CAAC;YAC1E,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,KAAK,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;YAC3E,CAAC;QACL,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,6BAAY,CAAC,qCAAqC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC9G,CAAC;IACL,CAAC;CACJ,CAAA;AAjCY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,qBAAU,GAAE;IAMJ,WAAA,IAAA,iBAAM,EAAC,qEAAiC,CAAC,uBAAuB,CAAC,CAAA;IAEjE,WAAA,IAAA,iBAAM,EAAC,qEAAiC,CAAC,kBAAkB,CAAC,CAAA;;GAPxD,wBAAwB,CAiCpC"}
|
package/docs/asyncapi.yaml
CHANGED
|
@@ -19,7 +19,7 @@ operations:
|
|
|
19
19
|
channels:
|
|
20
20
|
rush-hour-aggregation.aggregateData:
|
|
21
21
|
address: dataplatform.rush-hour-aggregation.aggregateData
|
|
22
|
-
description: Aggregate traffic data of a given type from a given time period to database. If the given time period contains too much data, the task will be split into multiple subtasks.
|
|
22
|
+
description: Aggregate traffic data of a given type from a given time period to database. If the given time period contains too much data, the task will be split into multiple subtasks. An empty message sends a separate message to this queue for each of the types FCD, NDIC, WAZEJ and WAZER with the time period of the last 10 minutes. SDDR is aggregated only by an explicit message, because its source no longer receives data.
|
|
23
23
|
bindings:
|
|
24
24
|
amqp:
|
|
25
25
|
is: queue
|
|
@@ -8,14 +8,14 @@ Modul agreguje dopravní data pro projekt Praha zasekaná.
|
|
|
8
8
|
|
|
9
9
|
Vstupem jsou 4 datové sady již existující v datové platformě:
|
|
10
10
|
|
|
11
|
-
- SDDŘ (TSK) - zdroj
|
|
12
|
-
- FCD -
|
|
13
|
-
- NDIC -
|
|
14
|
-
- Waze -
|
|
11
|
+
- SDDŘ (TSK) - zdroj archive.tsk_std_measurements, archive.tsk_std (archiv, poslední data z 28. 2. 2022)
|
|
12
|
+
- FCD - fcd.fcd_traff_params_part
|
|
13
|
+
- NDIC - ndic.ndic_traffic_info
|
|
14
|
+
- Waze - waze_ccp.wazeccp_jams
|
|
15
15
|
|
|
16
16
|
### Data aktivně stahujeme
|
|
17
17
|
|
|
18
|
-
Data se aktivně agregují pomocí cronu každých 5 minut. Kvůli možnému zpoždění obdržení některých dat je nastaven překryv a dohromady agreguje se posledních 10 minut. Existující položky jsou aktualizovaný na nový stav. Pro cron je nastavena priorita
|
|
18
|
+
Data se aktivně agregují pomocí cronu každých 5 minut. Kvůli možnému zpoždění obdržení některých dat je nastaven překryv a dohromady agreguje se posledních 10 minut. Existující položky jsou aktualizovaný na nový stav. Pravidelně se agregují typy FCD, NDIC, WAZEJ a WAZER. SDDŘ se pravidelně neagreguje, protože jeho zdroj už nedostává nová data. Lze ho agregovat jen ručně zprávou. Pro cron je nastavena priorita 5, pro VIP odbavení oproti historické agregaci viz níže.
|
|
19
19
|
|
|
20
20
|
Příklad nastavení cronu:
|
|
21
21
|
```json
|
|
@@ -44,16 +44,22 @@ Po nahraní dat do databáze se ještě "concurrently" obnoví nasledující mat
|
|
|
44
44
|
- ndic_events_full_snapshots_latest
|
|
45
45
|
- tsk_std_last_30min_snapshots_latest
|
|
46
46
|
- waze_jams_snapshots_latest
|
|
47
|
-
-
|
|
47
|
+
- waze_reconstructions_snapshots_latest
|
|
48
|
+
|
|
49
|
+
Latest pohledy porovnávají `measured_at` se začátkem dne v `int8`, aby se při obnově použil index na `measured_at` a četla se jen data aktuálního dne.
|
|
50
|
+
|
|
51
|
+
Celková doba agregace a uložení (včetně obnovy pohledu) se loguje na úrovni `info`.
|
|
52
|
+
|
|
53
|
+
Modul exportuje worker `RushHourAggregationWorker` (`AbstractWorker` z core), který registruje tasky `AggregateDataTask` a `RefreshHistoricViewsTask` z DI kontejneru `RushHourAggregationContainer`. Fronty mají prefix `dataplatform.rush-hour-aggregation`, jsou typu quorum s TTL 23 hodin. Zpráva pro `aggregateData` se validuje schématem `AggregateDataTaskInputSchema`.
|
|
48
54
|
|
|
49
55
|
Interní RabbitMQ fronty jsou popsány v [AsyncAPI](./asyncapi.yaml).
|
|
50
56
|
|
|
51
|
-
### *
|
|
57
|
+
### *RushHourAggregationWorker* - Task *AggregateDataTask* (fronta *aggregateData*):
|
|
52
58
|
|
|
53
59
|
Podporuje několik scénářů zpracovaní podle obdržené zprávy:
|
|
54
60
|
|
|
55
61
|
1) Prázdná zpráva
|
|
56
|
-
Je obvykle generována cronem
|
|
62
|
+
Je obvykle generována cronem. Pro každý pravidelně agregovaný typ (FCD, NDIC, WAZEJ, WAZER) pošle do stejné fronty samostatnou zprávu s obdobím posledních X minut dle nastavení workeru. V současnosti je tato hodnota nastavena na 10 minut. Každý typ tak běží jako samostatná úloha s vlastním timeoutem a pomalý typ neblokuje ostatní. Rozeslané zprávy i subtasky přebírají prioritu příchozí zprávy, takže pravidelná agregace (cron s prioritou 5) má dál přednost před historickou agregací.
|
|
57
63
|
|
|
58
64
|
2) Validní json zpráva
|
|
59
65
|
Validní json zpráva obsahuje údaje od, do a typ dat (v angličtině). Pro příklad zprávy viz readme modulu. Následně je zkontrolovano zda-li období zpracování není příliš dlouhé. Pro každý typ vstupních dat je toto období určeno jinak, dle množství generovaných dat a náročnosti zpracování:
|
|
@@ -68,7 +74,7 @@ Validní json zpráva obsahuje údaje od, do a typ dat (v angličtině). Pro př
|
|
|
68
74
|
Pokud je období dlouhé tak se rozdělí na subtasky, které se uloží do fronty ke zpracování.
|
|
69
75
|
V opačném případě se spustí agregační sql skript pro vybraný typ dat a výsledek se uloží do vybrané tabulky v db schématu praha_dopravni.
|
|
70
76
|
|
|
71
|
-
### *
|
|
77
|
+
### *RushHourAggregationWorker* - Task *RefreshHistoricViewsTask* (fronta *refreshHistoricViews*):
|
|
72
78
|
|
|
73
79
|
Je spuštěna cronem jednou za 24h s prázdnou zprávou a obnovuje "concurrently" historické pohledy, které připravují časová rozpětí pro již připravené agregace.
|
|
74
80
|
|
|
@@ -77,7 +83,7 @@ Seznam pohledů:
|
|
|
77
83
|
- ndic_events_full_snapshots_history
|
|
78
84
|
- tsk_std_last_30min_snapshots_history
|
|
79
85
|
- waze_jams_snapshots_history
|
|
80
|
-
-
|
|
86
|
+
- waze_reconstructions_snapshots_history
|
|
81
87
|
|
|
82
88
|
|
|
83
89
|
### Obecné
|
|
@@ -89,4 +95,4 @@ Seznam pohledů:
|
|
|
89
95
|
- migrační skripty
|
|
90
96
|
- ano, součastí modulu
|
|
91
97
|
- retence dat
|
|
92
|
-
-
|
|
98
|
+
- 3 měsíce, procedura `data_retention()` spouštěná v `refreshHistoricViews`
|
package/package.json
CHANGED
|
@@ -74,6 +74,9 @@ from
|
|
|
74
74
|
and gs.gs <= nti.validity_overall_end_time
|
|
75
75
|
and nti.situation_version_time <= gs.gs
|
|
76
76
|
and nti.global_network_linear is not null
|
|
77
|
+
and nti.validity_overall_end_time >= to_timestamp(((date_part('epoch'::text, (timestamp with time zone :from)) / (60 * 30)::double precision)::bigint * 60 * 30)::double precision)
|
|
78
|
+
and nti.validity_overall_start_time <= to_timestamp(((date_part('epoch'::text, (timestamp with time zone :to)) / (60 * 30)::double precision)::bigint * 60 * 30)::double precision)
|
|
79
|
+
and nti.situation_version_time <= to_timestamp(((date_part('epoch'::text, (timestamp with time zone :to)) / (60 * 30)::double precision)::bigint * 60 * 30)::double precision)
|
|
77
80
|
order by
|
|
78
81
|
gs.gs,
|
|
79
82
|
nti.situation_id,
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { BaseWorker } from "@golemio/core/dist/integration-engine";
|
|
2
|
-
import { Message } from "amqplib";
|
|
3
|
-
export declare class AggregationWorker extends BaseWorker {
|
|
4
|
-
static queuePrefix: string;
|
|
5
|
-
static aggregationMethodName: string;
|
|
6
|
-
static refreshHistoricViewsMethodName: string;
|
|
7
|
-
private aggregationFactory;
|
|
8
|
-
private refreshIntervalInMinutes;
|
|
9
|
-
private dataRetentionRepository;
|
|
10
|
-
constructor();
|
|
11
|
-
aggregateData: (message: Message) => Promise<void>;
|
|
12
|
-
refreshHistoricViews: () => Promise<void>;
|
|
13
|
-
private isTaskEmpty;
|
|
14
|
-
private isDateRangeBig;
|
|
15
|
-
private handleEmptyTask;
|
|
16
|
-
private processTask;
|
|
17
|
-
private generateSubTasks;
|
|
18
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AggregationWorker = void 0;
|
|
7
|
-
const AggregationTaskType_1 = require("../schema-definitions/helpers/AggregationTaskType");
|
|
8
|
-
const integration_engine_1 = require("@golemio/core/dist/integration-engine");
|
|
9
|
-
const config_1 = require("@golemio/core/dist/integration-engine/config");
|
|
10
|
-
const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
|
|
11
|
-
const luxon_1 = require("@golemio/core/dist/shared/luxon");
|
|
12
|
-
const WorkerHelper_1 = __importDefault(require("./WorkerHelper"));
|
|
13
|
-
const DataRetentionRepository_1 = require("./dataAccess/DataRetentionRepository");
|
|
14
|
-
const AggregationFactory_1 = __importDefault(require("./service/AggregationFactory"));
|
|
15
|
-
class AggregationWorker extends integration_engine_1.BaseWorker {
|
|
16
|
-
constructor() {
|
|
17
|
-
super();
|
|
18
|
-
this.refreshIntervalInMinutes = 10;
|
|
19
|
-
this.aggregateData = async (message) => {
|
|
20
|
-
const task = WorkerHelper_1.default.parseMessage(message);
|
|
21
|
-
integration_engine_1.log.debug(`Received new task: ${JSON.stringify(task)}`);
|
|
22
|
-
if (this.isTaskEmpty(task)) {
|
|
23
|
-
await this.handleEmptyTask();
|
|
24
|
-
}
|
|
25
|
-
else if (this.isDateRangeBig(task)) {
|
|
26
|
-
await this.generateSubTasks(task);
|
|
27
|
-
}
|
|
28
|
-
else if (task.type && task.from && task.to) {
|
|
29
|
-
await this.processTask(task.type, task.from, task.to, task.updateOnDuplicate, task.refreshView);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
throw new golemio_errors_1.GeneralError(`Unable to process task: ${JSON.stringify(task)}.`, this.constructor.name);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
this.refreshHistoricViews = async () => {
|
|
36
|
-
await this.dataRetentionRepository.deleteOldData();
|
|
37
|
-
for (const type in AggregationTaskType_1.AggregationTaskType) {
|
|
38
|
-
try {
|
|
39
|
-
const aggregator = this.aggregationFactory.get(type.toUpperCase());
|
|
40
|
-
await aggregator.refreshHistoricMaterialView();
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
integration_engine_1.log.error(`Unable to refresh historic material view for: ${type}. Error stack: ${err.stack}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
this.handleEmptyTask = async () => {
|
|
48
|
-
const to = new Date();
|
|
49
|
-
const from = luxon_1.DateTime.fromJSDate(to).minus({ minutes: this.refreshIntervalInMinutes }).toJSDate();
|
|
50
|
-
for (const type in AggregationTaskType_1.AggregationTaskType) {
|
|
51
|
-
await this.processTask(type, from, to, true, true);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
this.processTask = async (type, from, to, updateOnDuplicate, refreshView) => {
|
|
55
|
-
try {
|
|
56
|
-
const aggregator = this.aggregationFactory.get(type.toUpperCase());
|
|
57
|
-
await aggregator.aggregateAndSave(from, to, updateOnDuplicate, refreshView);
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
integration_engine_1.log.error(`Unable to process task: ${type} from: ${from} to: ${to}. (${err.toString()}) Error stack: ${err.stack}`);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
this.generateSubTasks = async (task) => {
|
|
64
|
-
const subtasks = WorkerHelper_1.default.generateSubTasksDefinitions(luxon_1.DateTime.fromJSDate(task.from), luxon_1.DateTime.fromJSDate(task.to), this.aggregationFactory.get(task.type).getMaxDuration(), task.type, task.updateOnDuplicate, task.refreshView);
|
|
65
|
-
for (const subtask of subtasks) {
|
|
66
|
-
await this.sendMessageToExchange("workers." + AggregationWorker.queuePrefix + "." + AggregationWorker.aggregationMethodName, JSON.stringify(subtask));
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
this.aggregationFactory = new AggregationFactory_1.default();
|
|
70
|
-
this.dataRetentionRepository = new DataRetentionRepository_1.DataRetentionRepository(integration_engine_1.PostgresConnector, integration_engine_1.log);
|
|
71
|
-
}
|
|
72
|
-
isTaskEmpty(task) {
|
|
73
|
-
return !task.from && !task.to && !task.type;
|
|
74
|
-
}
|
|
75
|
-
isDateRangeBig(task) {
|
|
76
|
-
if (task.from && task.to && task.type) {
|
|
77
|
-
const maxDuration = luxon_1.Duration.fromDurationLike(this.aggregationFactory.get(task.type).getMaxDuration());
|
|
78
|
-
const difference = luxon_1.DateTime.fromJSDate(task.to).diff(luxon_1.DateTime.fromJSDate(task.from), "hours");
|
|
79
|
-
return difference && difference > maxDuration;
|
|
80
|
-
}
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.AggregationWorker = AggregationWorker;
|
|
85
|
-
AggregationWorker.queuePrefix = config_1.config.RABBIT_EXCHANGE_NAME + "." + "rush-hour-aggregation";
|
|
86
|
-
AggregationWorker.aggregationMethodName = "aggregateData";
|
|
87
|
-
AggregationWorker.refreshHistoricViewsMethodName = "refreshHistoricViews";
|
|
88
|
-
//# sourceMappingURL=AggregationWorker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AggregationWorker.js","sourceRoot":"","sources":["../../src/integration-engine/AggregationWorker.ts"],"names":[],"mappings":";;;;;;AAAA,2FAAuE;AACvE,8EAA2F;AAC3F,yEAAsE;AACtE,6EAAwE;AACxE,2DAAqE;AAErE,kEAA0C;AAE1C,kFAA+E;AAC/E,sFAA8D;AAE9D,MAAa,iBAAkB,SAAQ,+BAAU;IAQ7C;QACI,KAAK,EAAE,CAAC;QAJJ,6BAAwB,GAAW,EAAE,CAAC;QASvC,kBAAa,GAAG,KAAK,EAAE,OAAgB,EAAE,EAAE;YAC9C,MAAM,IAAI,GAAG,sBAAY,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YAChD,wBAAG,CAAC,KAAK,CAAC,sBAAsB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACxD,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzB,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;YACjC,CAAC;iBAAM,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;gBACnC,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACtC,CAAC;iBAAM,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;gBAC3C,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CA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DAAuB,CAAC,sCAAiB,EAAE,wBAAG,CAAC,CAAC;IACvF,CAAC;IA6BO,WAAW,CAAC,IAAqB;QACrC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IAChD,CAAC;IAEO,cAAc,CAAC,IAAqB;QACxC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACpC,MAAM,WAAW,GAAG,gBAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC;YACvG,MAAM,UAAU,GAAG,gBAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,gBAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;YAE9F,OAAO,UAAU,IAAI,UAAU,GAAG,WAAW,CAAC;QAClD,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;;AAtDL,8CAgGC;AA/FiB,6BAAW,GAAG,eAAM,CAAC,oBAAoB,GAAG,GAAG,GAAG,uBAAuB,AAA9D,CAA+D;AAC1E,uCAAqB,GAAG,eAAe,AAAlB,CAAmB;AACxC,gDAA8B,GAAG,sBAAsB,AAAzB,CAA0B"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.queueDefinitions = void 0;
|
|
4
|
-
const config_1 = require("@golemio/core/dist/integration-engine/config");
|
|
5
|
-
const AggregationWorker_1 = require("./AggregationWorker");
|
|
6
|
-
const queueDefinitions = [
|
|
7
|
-
{
|
|
8
|
-
name: AggregationWorker_1.AggregationWorker.name,
|
|
9
|
-
queuePrefix: AggregationWorker_1.AggregationWorker.queuePrefix,
|
|
10
|
-
queues: [
|
|
11
|
-
{
|
|
12
|
-
name: AggregationWorker_1.AggregationWorker.aggregationMethodName,
|
|
13
|
-
options: {
|
|
14
|
-
deadLetterExchange: config_1.config.RABBIT_EXCHANGE_NAME,
|
|
15
|
-
deadLetterRoutingKey: "dead",
|
|
16
|
-
messageTtl: 23 * 60 * 60 * 1000, // 23 hours
|
|
17
|
-
arguments: { "x-queue-type": "quorum" },
|
|
18
|
-
},
|
|
19
|
-
worker: AggregationWorker_1.AggregationWorker,
|
|
20
|
-
workerMethod: AggregationWorker_1.AggregationWorker.aggregationMethodName,
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
name: AggregationWorker_1.AggregationWorker.refreshHistoricViewsMethodName,
|
|
24
|
-
options: {
|
|
25
|
-
deadLetterExchange: config_1.config.RABBIT_EXCHANGE_NAME,
|
|
26
|
-
deadLetterRoutingKey: "dead",
|
|
27
|
-
messageTtl: 23 * 60 * 60 * 1000, // 23 hours
|
|
28
|
-
},
|
|
29
|
-
worker: AggregationWorker_1.AggregationWorker,
|
|
30
|
-
workerMethod: AggregationWorker_1.AggregationWorker.refreshHistoricViewsMethodName,
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
},
|
|
34
|
-
];
|
|
35
|
-
exports.queueDefinitions = queueDefinitions;
|
|
36
|
-
//# sourceMappingURL=queueDefinitions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queueDefinitions.js","sourceRoot":"","sources":["../../src/integration-engine/queueDefinitions.ts"],"names":[],"mappings":";;;AAAA,yEAAsE;AAEtE,2DAAwD;AAExD,MAAM,gBAAgB,GAAuB;IACzC;QACI,IAAI,EAAE,qCAAiB,CAAC,IAAI;QAC5B,WAAW,EAAE,qCAAiB,CAAC,WAAW;QAC1C,MAAM,EAAE;YACJ;gBACI,IAAI,EAAE,qCAAiB,CAAC,qBAAqB;gBAC7C,OAAO,EAAE;oBACL,kBAAkB,EAAE,eAAM,CAAC,oBAAoB;oBAC/C,oBAAoB,EAAE,MAAM;oBAC5B,UAAU,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,WAAW;oBAC5C,SAAS,EAAE,EAAE,cAAc,EAAE,QAAQ,EAAE;iBAC1C;gBACD,MAAM,EAAE,qCAAiB;gBACzB,YAAY,EAAE,qCAAiB,CAAC,qBAAqB;aACxD;YACD;gBACI,IAAI,EAAE,qCAAiB,CAAC,8BAA8B;gBACtD,OAAO,EAAE;oBACL,kBAAkB,EAAE,eAAM,CAAC,oBAAoB;oBAC/C,oBAAoB,EAAE,MAAM;oBAC5B,UAAU,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,WAAW;iBAC/C;gBACD,MAAM,EAAE,qCAAiB;gBACzB,YAAY,EAAE,qCAAiB,CAAC,8BAA8B;aACjE;SACJ;KACJ;CACJ,CAAC;AAEO,4CAAgB"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# Udržování changelogu v projektech
|
|
2
|
-
|
|
3
|
-
_Tohle je výstup z [general#345](https://gitlab.com/operator-ict/golemio/code/general/-/issues/345)_
|
|
4
|
-
|
|
5
|
-
Začínáme zavádět changelogy podle [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) a semantického verzování
|
|
6
|
-
|
|
7
|
-
```markdown
|
|
8
|
-
## [version] - release date
|
|
9
|
-
|
|
10
|
-
### type of action
|
|
11
|
-
|
|
12
|
-
- Description (([project#issue](link to the issue)))
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
- Během vývoje a code reviews je potřeba kontrolovat existenci CHANGELOG.md a zda byl přidán záznam do Unreleased sekce pod správný typ změny
|
|
16
|
-
- Added
|
|
17
|
-
- Changed
|
|
18
|
-
- Deprecated
|
|
19
|
-
- Removed
|
|
20
|
-
- Fixed
|
|
21
|
-
- Security
|
|
22
|
-
- Rovněž je potřeba ujistit, že aktuální kopie [keeping_a_changelog.md](/introduction/keeping_a_changelog.md) se nachází ve složce _docs/_, pokud tam už není
|
|
23
|
-
- Před releasem nahradit Unreleased za _[version] - release date_
|
|
24
|
-
- Po release bumpnout verzi a přidat novou Unreleased sekci (v případě částečného release přesunout nenasazené změny do Unreleased)
|
|
25
|
-
|
|
26
|
-
**Příklad changelogu pro pid modul**
|
|
27
|
-
```markdown
|
|
28
|
-
# Changelog
|
|
29
|
-
|
|
30
|
-
All notable changes to this project will be documented in this file.
|
|
31
|
-
|
|
32
|
-
## [Unreleased]
|
|
33
|
-
|
|
34
|
-
### Added
|
|
35
|
-
|
|
36
|
-
- Modularized migrations ([pid#53](https://gitlab.com/operator-ict/golemio/code/modules/pid/-/issues/53))
|
|
37
|
-
|
|
38
|
-
## [2.0.12] - 2021-10-18
|
|
39
|
-
|
|
40
|
-
### Fixed
|
|
41
|
-
|
|
42
|
-
- Empty array of tripsIds in updateDelay
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
**Příklad projektů se zavedeným changelogem**
|
|
46
|
-
|
|
47
|
-
- [Golemio CLI](https://gitlab.com/operator-ict/golemio/code/golemio-cli/-/blob/development/CHANGELOG.md)
|
|
48
|
-
- [PID Module](https://gitlab.com/operator-ict/golemio/code/modules/pid/-/blob/development/CHANGELOG.md)
|