@ikonintegration/ikapi 3.1.28 → 3.1.31
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikonintegration/ikapi",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.31",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "main.js",
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"author": "",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
15
|
-
"@aws-sdk/client-ses": "^3.
|
|
16
|
-
"@aws-sdk/client-sns": "^3.
|
|
17
|
-
"@aws-sdk/credential-provider-node": "^3.
|
|
14
|
+
"@aws-sdk/client-dynamodb": "^3.145.0",
|
|
15
|
+
"@aws-sdk/client-ses": "^3.145.0",
|
|
16
|
+
"@aws-sdk/client-sns": "^3.145.0",
|
|
17
|
+
"@aws-sdk/credential-provider-node": "^3.145.0",
|
|
18
18
|
"@aws-sdk/node-http-handler": "^3.127.0",
|
|
19
|
-
"@aws-sdk/util-dynamodb": "^3.
|
|
20
|
-
"@ikonintegration/mod-resources-tracker-client": "0.0.
|
|
19
|
+
"@aws-sdk/util-dynamodb": "^3.145.0",
|
|
20
|
+
"@ikonintegration/mod-resources-tracker-client": "0.0.18",
|
|
21
21
|
"abind": "^1.0.5",
|
|
22
22
|
"bluebird": "^3.7.2",
|
|
23
23
|
"email-templates": "^8.0.8",
|
|
@@ -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.trackExecAndDrain(
|
|
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.trackExecAndDrain(
|
|
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);
|
|
@@ -10,6 +10,7 @@ export default class IKExecutionTracker {
|
|
|
10
10
|
this.db = db;
|
|
11
11
|
this.config = config;
|
|
12
12
|
this.startedOn = Date.now();
|
|
13
|
+
this.drainedExecution = false;
|
|
13
14
|
if (config) this.client = this._getClient(config);
|
|
14
15
|
this.claimers = {};
|
|
15
16
|
}
|
|
@@ -17,37 +18,42 @@ export default class IKExecutionTracker {
|
|
|
17
18
|
appendClaimer(value, key) { this.claimers[value] = key; }
|
|
18
19
|
appendEvent(event) { this.client.appendEvent(event); }
|
|
19
20
|
//
|
|
21
|
+
resetExecutionTrace() {
|
|
22
|
+
this.startedOn = Date.now();
|
|
23
|
+
this.drainedExecution = false;
|
|
24
|
+
}
|
|
20
25
|
async quickDrain() {
|
|
21
26
|
try {
|
|
22
|
-
//Check for client
|
|
23
|
-
if (!this.client
|
|
24
|
-
//drain stats
|
|
27
|
+
//Check for client but claimers
|
|
28
|
+
if (!this.client) return; //disabled
|
|
29
|
+
//drain stats (drain will filter for events with claimers only)
|
|
25
30
|
await this.client.drain(this.claimers);
|
|
26
31
|
} catch (e) { console.error(`Error while draining tracker events: ${e}`); }
|
|
27
32
|
}
|
|
28
|
-
async trackExecAndDrain(
|
|
33
|
+
async trackExecAndDrain() {
|
|
29
34
|
try {
|
|
35
|
+
//Check
|
|
36
|
+
if (this.drainedExecution) return;
|
|
37
|
+
this.drainedExecution = true;
|
|
30
38
|
//Check for client and claimers
|
|
31
|
-
if (!this.client
|
|
32
|
-
//Check for config
|
|
33
|
-
if (isAutotracking && this.config.disableAutoTracking) return; //disabled
|
|
39
|
+
if (!this.client) return; //disabled
|
|
34
40
|
//detect execution and log (ECS or lambda)
|
|
35
|
-
this._detectExecutionAndLog(
|
|
41
|
+
this._detectExecutionAndLog();
|
|
36
42
|
//detect DB and log (DDB only for now)
|
|
37
43
|
this._collectDDBStats();
|
|
38
|
-
//drain stats
|
|
44
|
+
//drain stats (drain will filter for events with claimers only)
|
|
39
45
|
await this.client.drain(this.claimers);
|
|
40
46
|
} catch (e) { console.error(`Error while tracking execution: ${e}`); }
|
|
41
47
|
}
|
|
42
48
|
/* private tracker */
|
|
43
|
-
_detectExecutionAndLog(
|
|
49
|
+
_detectExecutionAndLog() {
|
|
44
50
|
//Is running on container?
|
|
45
51
|
if (Utils.isHybridlessContainer()) {
|
|
46
52
|
//ECS, get metadata info and log if applicable and succeeded on it
|
|
47
53
|
const context = this._getECSMetadataObject();
|
|
48
54
|
// console.debug('Context', context);
|
|
49
55
|
if (context && context.ContainerInstanceARN) {
|
|
50
|
-
const extraDetails = { startTime: this.startedOn, endTime:
|
|
56
|
+
const extraDetails = { startTime: this.startedOn, endTime: Date.now(), taskConfig: { cpu: process.env.CPU, memory: process.env.MEMORY, taskName: context.TaskDefinitionFamily } };
|
|
51
57
|
const event = RTClient.newECSExecutionEvent(context.TaskARN, context.ContainerInstanceARN, extraDetails);
|
|
52
58
|
this.appendEvent(event);
|
|
53
59
|
}
|