@ikonintegration/ikapi 3.1.27 → 3.1.30
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/package.json
CHANGED
|
@@ -28,14 +28,16 @@ export default class IKProcess {
|
|
|
28
28
|
//Main interface
|
|
29
29
|
async execute(executionFunc) {
|
|
30
30
|
this.logger.debug("Starting main process code");
|
|
31
|
+
//Tracker
|
|
32
|
+
if (this.allowExecutionIdentification && this.tracker) this.tracker.resetExecutionTrace();
|
|
31
33
|
//Connect DB
|
|
32
34
|
if (this.db) await this.db.connect();
|
|
33
|
-
//
|
|
35
|
+
//Program loop
|
|
34
36
|
setInterval( async () => {
|
|
35
37
|
await this._execute(executionFunc);
|
|
36
38
|
}, this.interval);
|
|
37
|
-
//
|
|
38
|
-
if (this.allowExecutionIdentification && this.tracker) await this.tracker.
|
|
39
|
+
//Tracker
|
|
40
|
+
if (this.allowExecutionIdentification && this.tracker) await this.tracker.trackExecAndDrain();
|
|
39
41
|
}
|
|
40
42
|
//Executions
|
|
41
43
|
async _execute(executionFunc) {
|
|
@@ -53,6 +53,8 @@ export default class IKTransaction {
|
|
|
53
53
|
try { //Execute
|
|
54
54
|
this.logger.debug("Starting main request code");
|
|
55
55
|
this._resp = await executionFunc(this);
|
|
56
|
+
//Tracker after successful execution (before succeeding the context, which will cause things to die)
|
|
57
|
+
if (this.tracker) await this.tracker.trackExecAndDrain();
|
|
56
58
|
//Answer client
|
|
57
59
|
if (this._resp && this._resp instanceof IKResponse) {
|
|
58
60
|
await this._resp.build(this._context, this, this._syncReturn);
|
|
@@ -102,8 +104,8 @@ export default class IKTransaction {
|
|
|
102
104
|
try {
|
|
103
105
|
await safeExecution();
|
|
104
106
|
await this.logger.flushLogs();
|
|
105
|
-
//Tracker
|
|
106
|
-
if (this.tracker) await this.tracker.
|
|
107
|
+
//Tracker (if not tracked yet -- exception case)
|
|
108
|
+
if (this.tracker) await this.tracker.trackExecAndDrain();
|
|
107
109
|
} catch (e) {
|
|
108
110
|
this.logger.error('Exception when flushing logs.');
|
|
109
111
|
this.logger.exception(e);
|
|
@@ -8,7 +8,9 @@ export default class IKExecutionTracker {
|
|
|
8
8
|
constructor(config, context, db) {
|
|
9
9
|
this.context = context;
|
|
10
10
|
this.db = db;
|
|
11
|
+
this.config = config;
|
|
11
12
|
this.startedOn = Date.now();
|
|
13
|
+
this.drainedExecution = false;
|
|
12
14
|
if (config) this.client = this._getClient(config);
|
|
13
15
|
this.claimers = {};
|
|
14
16
|
}
|
|
@@ -16,6 +18,10 @@ export default class IKExecutionTracker {
|
|
|
16
18
|
appendClaimer(value, key) { this.claimers[value] = key; }
|
|
17
19
|
appendEvent(event) { this.client.appendEvent(event); }
|
|
18
20
|
//
|
|
21
|
+
resetExecutionTrace() {
|
|
22
|
+
this.startedOn = Date.now();
|
|
23
|
+
this.drainedExecution = false;
|
|
24
|
+
}
|
|
19
25
|
async quickDrain() {
|
|
20
26
|
try {
|
|
21
27
|
//Check for client and claimers
|
|
@@ -24,8 +30,11 @@ export default class IKExecutionTracker {
|
|
|
24
30
|
await this.client.drain(this.claimers);
|
|
25
31
|
} catch (e) { console.error(`Error while draining tracker events: ${e}`); }
|
|
26
32
|
}
|
|
27
|
-
async
|
|
33
|
+
async trackExecAndDrain() {
|
|
28
34
|
try {
|
|
35
|
+
//Check
|
|
36
|
+
if (this.drainedExecution) return;
|
|
37
|
+
this.drainedExecution = true;
|
|
29
38
|
//Check for client and claimers
|
|
30
39
|
if (!this.client || Object.keys(this.claimers).length == 0) return; //disabled
|
|
31
40
|
//detect execution and log (ECS or lambda)
|