@ikonintegration/ikapi 3.1.28 → 3.1.29
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,13 +28,15 @@ 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
|
-
//
|
|
39
|
+
//Tracker
|
|
38
40
|
if (this.allowExecutionIdentification && this.tracker) await this.tracker.trackExecAndDrain(true);
|
|
39
41
|
}
|
|
40
42
|
//Executions
|
|
@@ -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,6 +18,10 @@ 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
27
|
//Check for client and claimers
|
|
@@ -25,14 +30,15 @@ export default class IKExecutionTracker {
|
|
|
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
39
|
if (!this.client || Object.keys(this.claimers).length == 0) return; //disabled
|
|
32
|
-
//Check for config
|
|
33
|
-
if (isAutotracking && this.config.disableAutoTracking) 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
44
|
//drain stats
|
|
@@ -40,14 +46,14 @@ export default class IKExecutionTracker {
|
|
|
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
|
}
|