@cumulus/message 10.1.1 → 11.1.0
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/Collections.d.ts +3 -0
- package/Collections.d.ts.map +1 -1
- package/Collections.js +7 -5
- package/Collections.js.map +1 -1
- package/Executions.d.ts +19 -4
- package/Executions.d.ts.map +1 -1
- package/Executions.js +51 -3
- package/Executions.js.map +1 -1
- package/Granules.d.ts +76 -10
- package/Granules.d.ts.map +1 -1
- package/Granules.js +141 -2
- package/Granules.js.map +1 -1
- package/PDRs.d.ts +18 -12
- package/PDRs.d.ts.map +1 -1
- package/PDRs.js +73 -4
- package/PDRs.js.map +1 -1
- package/README.md +132 -28
- package/package.json +7 -7
- package/src/Collections.ts +4 -1
- package/src/Executions.ts +77 -7
- package/src/Granules.ts +218 -3
- package/src/PDRs.ts +99 -13
- package/src/types.ts +5 -0
- package/src/utils.ts +17 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/types.d.ts +4 -0
- package/types.d.ts.map +1 -1
- package/utils.d.ts +8 -0
- package/utils.d.ts.map +1 -0
- package/utils.js +26 -0
- package/utils.js.map +1 -0
package/PDRs.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPdrPercentCompletion = exports.getMessagePdrStats = exports.getMessagePdrFailedExecutions = exports.getMessagePdrCompletedExecutions = exports.getMessagePdrRunningExecutions = exports.getMessagePdrName = exports.getMessagePdrPANMessage = exports.getMessagePdrPANSent = exports.messageHasPdr = exports.getMessagePdr = void 0;
|
|
6
|
+
exports.generatePdrApiRecordFromMessage = exports.getPdrPercentCompletion = exports.getMessagePdrStats = exports.getMessagePdrFailedExecutions = exports.getMessagePdrCompletedExecutions = exports.getMessagePdrRunningExecutions = exports.getMessagePdrName = exports.getMessagePdrPANMessage = exports.getMessagePdrPANSent = exports.messageHasPdr = exports.getMessagePdr = void 0;
|
|
7
|
+
const errors_1 = require("@cumulus/errors");
|
|
8
|
+
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
9
|
+
const Collections_1 = require("./Collections");
|
|
10
|
+
const Executions_1 = require("./Executions");
|
|
11
|
+
const Providers_1 = require("./Providers");
|
|
12
|
+
const workflows_1 = require("./workflows");
|
|
13
|
+
const logger = new logger_1.default({ sender: '@cumulus/message/PDRs' });
|
|
4
14
|
/**
|
|
5
15
|
* Get the PDR object from a workflow message, if any.
|
|
6
16
|
*
|
|
@@ -54,7 +64,7 @@ exports.getMessagePdrName = getMessagePdrName;
|
|
|
54
64
|
/**
|
|
55
65
|
* Get the number of running executions for a PDR, if any.
|
|
56
66
|
*
|
|
57
|
-
* @param {
|
|
67
|
+
* @param {MessageWithOptionalPayloadPdr} message - A workflow message
|
|
58
68
|
* @returns {number} Number of running executions
|
|
59
69
|
*
|
|
60
70
|
* @alias module:PDRs
|
|
@@ -64,7 +74,7 @@ exports.getMessagePdrRunningExecutions = getMessagePdrRunningExecutions;
|
|
|
64
74
|
/**
|
|
65
75
|
* Get the number of completed executions for a PDR, if any.
|
|
66
76
|
*
|
|
67
|
-
* @param {
|
|
77
|
+
* @param {MessageWithOptionalPayloadPdr} message - A workflow message
|
|
68
78
|
* @returns {number} Number of completed executions
|
|
69
79
|
*
|
|
70
80
|
* @alias module:PDRs
|
|
@@ -74,7 +84,7 @@ exports.getMessagePdrCompletedExecutions = getMessagePdrCompletedExecutions;
|
|
|
74
84
|
/**
|
|
75
85
|
* Get the number of failed executions for a PDR, if any.
|
|
76
86
|
*
|
|
77
|
-
* @param {
|
|
87
|
+
* @param {MessageWithOptionalPayloadPdr} message - A workflow message
|
|
78
88
|
* @returns {number} Number of failed executions
|
|
79
89
|
*
|
|
80
90
|
* @alias module:PDRs
|
|
@@ -122,4 +132,63 @@ const getPdrPercentCompletion = (stats) => {
|
|
|
122
132
|
return progress;
|
|
123
133
|
};
|
|
124
134
|
exports.getPdrPercentCompletion = getPdrPercentCompletion;
|
|
135
|
+
/**
|
|
136
|
+
* Generate a PDR record for the API from the message.
|
|
137
|
+
*
|
|
138
|
+
* @param {MessageWithOptionalPayloadPdr} message - A workflow message object
|
|
139
|
+
* @param {string} [updatedAt] - Optional updated timestamp to apply to record
|
|
140
|
+
* @returns {ExecutionRecord} An PDR API record
|
|
141
|
+
*
|
|
142
|
+
* @alias module:Executions
|
|
143
|
+
*/
|
|
144
|
+
const generatePdrApiRecordFromMessage = (message, updatedAt = Date.now()) => {
|
|
145
|
+
const pdr = (0, exports.getMessagePdr)(message);
|
|
146
|
+
// We got a message with no PDR (OK)
|
|
147
|
+
if (!pdr) {
|
|
148
|
+
logger.info('No PDRs to process on the message');
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
// We got a message with a PDR but no name to identify it (Not OK)
|
|
152
|
+
if (!pdr.name) {
|
|
153
|
+
throw new errors_1.CumulusMessageError(`Could not find name on PDR object ${JSON.stringify(pdr)}`);
|
|
154
|
+
}
|
|
155
|
+
const collectionId = (0, Collections_1.getCollectionIdFromMessage)(message);
|
|
156
|
+
if (!collectionId) {
|
|
157
|
+
throw new errors_1.CumulusMessageError('meta.collection required to generate a PDR record');
|
|
158
|
+
}
|
|
159
|
+
const providerId = (0, Providers_1.getMessageProviderId)(message);
|
|
160
|
+
if (!providerId) {
|
|
161
|
+
throw new errors_1.CumulusMessageError('meta.provider required to generate a PDR record');
|
|
162
|
+
}
|
|
163
|
+
const status = (0, workflows_1.getMetaStatus)(message);
|
|
164
|
+
if (!status) {
|
|
165
|
+
throw new errors_1.CumulusMessageError('meta.status required to generate a PDR record');
|
|
166
|
+
}
|
|
167
|
+
const arn = (0, Executions_1.getMessageExecutionArn)(message);
|
|
168
|
+
if (!arn) {
|
|
169
|
+
throw new errors_1.CumulusMessageError('cumulus_meta.state_machine and cumulus_meta.execution_name required to generate a PDR record');
|
|
170
|
+
}
|
|
171
|
+
const execution = (0, Executions_1.getExecutionUrlFromArn)(arn);
|
|
172
|
+
const stats = (0, exports.getMessagePdrStats)(message);
|
|
173
|
+
const progress = (0, exports.getPdrPercentCompletion)(stats);
|
|
174
|
+
const now = Date.now();
|
|
175
|
+
const workflowStartTime = (0, workflows_1.getMessageWorkflowStartTime)(message);
|
|
176
|
+
const record = {
|
|
177
|
+
pdrName: pdr.name,
|
|
178
|
+
collectionId,
|
|
179
|
+
status,
|
|
180
|
+
provider: providerId,
|
|
181
|
+
progress,
|
|
182
|
+
execution,
|
|
183
|
+
PANSent: (0, exports.getMessagePdrPANSent)(message),
|
|
184
|
+
PANmessage: (0, exports.getMessagePdrPANMessage)(message),
|
|
185
|
+
stats,
|
|
186
|
+
createdAt: (0, workflows_1.getMessageWorkflowStartTime)(message),
|
|
187
|
+
timestamp: now,
|
|
188
|
+
updatedAt,
|
|
189
|
+
duration: (0, workflows_1.getWorkflowDuration)(workflowStartTime, now),
|
|
190
|
+
};
|
|
191
|
+
return record;
|
|
192
|
+
};
|
|
193
|
+
exports.generatePdrApiRecordFromMessage = generatePdrApiRecordFromMessage;
|
|
125
194
|
//# sourceMappingURL=PDRs.js.map
|
package/PDRs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PDRs.js","sourceRoot":"","sources":["src/PDRs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PDRs.js","sourceRoot":"","sources":["src/PDRs.ts"],"names":[],"mappings":";;;;;;AAAA,4CAEyB;AACzB,6DAAqC;AAIrC,+CAA2D;AAC3D,6CAGsB;AACtB,2CAEqB;AACrB,2CAIqB;AAErB,MAAM,MAAM,GAAG,IAAI,gBAAM,CAAC,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC,CAAC;AAwB/D;;;;;;;GAOG;AACI,MAAM,aAAa,GAAG,CAC3B,OAAsC,EACrB,EA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C,GAAG,EAAE,CAAC;IACvB,MAAM,iBAAiB,GAAG,IAAA,uCAA2B,EAAC,OAAO,CAAC,CAAC;IAE/D,MAAM,MAAM,GAAG;QACb,OAAO,EAAE,GAAG,CAAC,IAAI;QACjB,YAAY;QACZ,MAAM;QACN,QAAQ,EAAE,UAAU;QACpB,QAAQ;QACR,SAAS;QACT,OAAO,EAAE,IAAA,4BAAoB,EAAC,OAAO,CAAC;QACtC,UAAU,EAAE,IAAA,+BAAuB,EAAC,OAAO,CAAC;QAC5C,KAAK;QACL,SAAS,EAAE,IAAA,uCAA2B,EAAC,OAAO,CAAC;QAC/C,SAAS,EAAE,GAAG;QACd,SAAS;QACT,QAAQ,EAAE,IAAA,+BAAmB,EAAC,iBAAiB,EAAE,GAAG,CAAC;KACtD,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA5DW,QAAA,+BAA+B,mCA4D1C"}
|
package/README.md
CHANGED
|
@@ -20,6 +20,9 @@ Utilities for building and parsing Cumulus workflow messages.
|
|
|
20
20
|
<dd><p>Utility functions for generating execution information or parsing execution information
|
|
21
21
|
from a Cumulus message</p>
|
|
22
22
|
</dd>
|
|
23
|
+
<dt><a href="#module_Granules">Granules</a></dt>
|
|
24
|
+
<dd><p>Utility functions for parsing granule information from a Cumulus message</p>
|
|
25
|
+
</dd>
|
|
23
26
|
<dt><a href="#module_Queue">Queue</a></dt>
|
|
24
27
|
<dd><p>Utility functions for parsing queue information from a Cumulus message</p>
|
|
25
28
|
</dd>
|
|
@@ -34,7 +37,7 @@ from a Cumulus message</p>
|
|
|
34
37
|
<dt><a href="#exp_module_Collections--constructCollectionId">constructCollectionId(name, version)</a> ⇒ <code>string</code> ⏏</dt>
|
|
35
38
|
<dd><p>Returns the collection ID.</p>
|
|
36
39
|
</dd>
|
|
37
|
-
<dt><a href="#deconstructCollectionId">deconstructCollectionId(collectionId)</a> ⇒ <code>Object</code
|
|
40
|
+
<dt><a href="#exp_module_Collections--deconstructCollectionId">deconstructCollectionId(collectionId)</a> ⇒ <code>Object</code> ⏏</dt>
|
|
38
41
|
<dd><p>Returns the name and version of a collection based on
|
|
39
42
|
the collectionId used in elasticsearch indexing</p>
|
|
40
43
|
</dd>
|
|
@@ -48,18 +51,6 @@ the collectionId used in elasticsearch indexing</p>
|
|
|
48
51
|
<dd><p>Unwrap dead letter Cumulus message, which may be wrapped in a
|
|
49
52
|
States cloudwatch event, which is wrapped in an SQS message.</p>
|
|
50
53
|
</dd>
|
|
51
|
-
<dt><a href="#exp_module_Granules--getMessageGranules">getMessageGranules(message)</a> ⇒ <code>Array.<Object></code> | <code>undefined</code> ⏏</dt>
|
|
52
|
-
<dd><p>Get granules from payload?.granules of a workflow message.</p>
|
|
53
|
-
</dd>
|
|
54
|
-
<dt><a href="#exp_module_Granules--messageHasGranules">messageHasGranules(message)</a> ⇒ <code>boolean</code> ⏏</dt>
|
|
55
|
-
<dd><p>Determine if message has a granules object.</p>
|
|
56
|
-
</dd>
|
|
57
|
-
<dt><a href="#exp_module_Granules--getGranuleStatus">getGranuleStatus(workflowStatus, granule)</a> ⇒ <code>string</code> ⏏</dt>
|
|
58
|
-
<dd><p>Determine the status of a granule.</p>
|
|
59
|
-
</dd>
|
|
60
|
-
<dt><a href="#exp_module_Granules--getGranuleQueryFields">getGranuleQueryFields(message)</a> ⇒ <code>unknown</code> | <code>undefined</code> ⏏</dt>
|
|
61
|
-
<dd><p>Get the query fields of a granule, if any</p>
|
|
62
|
-
</dd>
|
|
63
54
|
<dt><a href="#exp_module_PDRs--getMessagePdr">getMessagePdr(message)</a> ⇒ <code>undefined</code> | <code>Object</code> ⏏</dt>
|
|
64
55
|
<dd><p>Get the PDR object from a workflow message, if any.</p>
|
|
65
56
|
</dd>
|
|
@@ -90,6 +81,9 @@ States cloudwatch event, which is wrapped in an SQS message.</p>
|
|
|
90
81
|
<dt><a href="#exp_module_PDRs--getPdrPercentCompletion">getPdrPercentCompletion(stats)</a> ⇒ <code>number</code> ⏏</dt>
|
|
91
82
|
<dd><p>Get the percent completion of PDR executions</p>
|
|
92
83
|
</dd>
|
|
84
|
+
<dt><a href="#exp_module_Executions--generatePdrApiRecordFromMessage">generatePdrApiRecordFromMessage(message, [updatedAt])</a> ⇒ <code>ExecutionRecord</code> ⏏</dt>
|
|
85
|
+
<dd><p>Generate a PDR record for the API from the message.</p>
|
|
86
|
+
</dd>
|
|
93
87
|
<dt><a href="#exp_module_Providers--getMessageProvider">getMessageProvider(message)</a> ⇒ <code>MessageProvider</code> | <code>string</code> ⏏</dt>
|
|
94
88
|
<dd><p>Get the provider from a workflow message, if any.</p>
|
|
95
89
|
</dd>
|
|
@@ -119,6 +113,9 @@ update the status of any granules/PDRs that don't exist in the initial execu
|
|
|
119
113
|
input.</p>
|
|
120
114
|
<p>Falls back to overall execution input.</p>
|
|
121
115
|
</dd>
|
|
116
|
+
<dt><a href="#parseException">parseException(exception)</a> ⇒ <code>string</code></dt>
|
|
117
|
+
<dd><p>Ensures that the exception is returned as an object</p>
|
|
118
|
+
</dd>
|
|
122
119
|
<dt><a href="#exp_module_workflows--getMetaStatus">getMetaStatus(message)</a> ⇒ <code>Message.WorkflowStatus</code> | <code>undefined</code> ⏏</dt>
|
|
123
120
|
<dd><p>Get the status of a workflow message, if any.</p>
|
|
124
121
|
</dd>
|
|
@@ -192,6 +189,9 @@ const Executions = require('@cumulus/message/Executions');
|
|
|
192
189
|
* [getMessageCumulusVersion(message)](#exp_module_Executions--getMessageCumulusVersion) ⇒ <code>undefined</code> \| <code>string</code> ⏏
|
|
193
190
|
* [getMessageExecutionOriginalPayload(message)](#exp_module_Executions--getMessageExecutionOriginalPayload) ⇒ <code>unknown</code> \| <code>undefined</code> ⏏
|
|
194
191
|
* [getMessageExecutionFinalPayload(message)](#exp_module_Executions--getMessageExecutionFinalPayload) ⇒ <code>unknown</code> \| <code>undefined</code> ⏏
|
|
192
|
+
* [generateExecutionApiRecordFromMessage(message, [updatedAt])](#exp_module_Executions--generateExecutionApiRecordFromMessage) ⇒ <code>ExecutionRecord</code> ⏏
|
|
193
|
+
* _global_
|
|
194
|
+
* [generatePdrApiRecordFromMessage(message, [updatedAt])](#exp_module_Executions--generatePdrApiRecordFromMessage) ⇒ <code>ExecutionRecord</code> ⏏
|
|
195
195
|
|
|
196
196
|
<a name="exp_module_Executions--buildExecutionArn"></a>
|
|
197
197
|
|
|
@@ -308,7 +308,7 @@ Get the workflow original payload, if any.
|
|
|
308
308
|
|
|
309
309
|
| Param | Type | Description |
|
|
310
310
|
| --- | --- | --- |
|
|
311
|
-
| message | <code>
|
|
311
|
+
| message | <code>MessageWithPayload</code> | A workflow message object |
|
|
312
312
|
|
|
313
313
|
<a name="exp_module_Executions--getMessageExecutionFinalPayload"></a>
|
|
314
314
|
|
|
@@ -320,7 +320,112 @@ Get the workflow final payload, if any.
|
|
|
320
320
|
|
|
321
321
|
| Param | Type | Description |
|
|
322
322
|
| --- | --- | --- |
|
|
323
|
-
| message | <code>
|
|
323
|
+
| message | <code>MessageWithPayload</code> | A workflow message object |
|
|
324
|
+
|
|
325
|
+
<a name="exp_module_Executions--generateExecutionApiRecordFromMessage"></a>
|
|
326
|
+
|
|
327
|
+
#### generateExecutionApiRecordFromMessage(message, [updatedAt]) ⇒ <code>ExecutionRecord</code> ⏏
|
|
328
|
+
Generate an execution record for the API from the message.
|
|
329
|
+
|
|
330
|
+
**Kind**: Exported function
|
|
331
|
+
**Returns**: <code>ExecutionRecord</code> - An execution API record
|
|
332
|
+
|
|
333
|
+
| Param | Type | Description |
|
|
334
|
+
| --- | --- | --- |
|
|
335
|
+
| message | <code>MessageWithPayload</code> | A workflow message object |
|
|
336
|
+
| [updatedAt] | <code>string</code> | Optional updated timestamp to apply to record |
|
|
337
|
+
|
|
338
|
+
<a name="exp_module_Executions--generatePdrApiRecordFromMessage"></a>
|
|
339
|
+
|
|
340
|
+
#### generatePdrApiRecordFromMessage(message, [updatedAt]) ⇒ <code>ExecutionRecord</code> ⏏
|
|
341
|
+
Generate a PDR record for the API from the message.
|
|
342
|
+
|
|
343
|
+
**Kind**: global method of [<code>Executions</code>](#module_Executions)
|
|
344
|
+
**Returns**: <code>ExecutionRecord</code> - An PDR API record
|
|
345
|
+
|
|
346
|
+
| Param | Type | Description |
|
|
347
|
+
| --- | --- | --- |
|
|
348
|
+
| message | <code>MessageWithOptionalPayloadPdr</code> | A workflow message object |
|
|
349
|
+
| [updatedAt] | <code>string</code> | Optional updated timestamp to apply to record |
|
|
350
|
+
|
|
351
|
+
<a name="module_Granules"></a>
|
|
352
|
+
|
|
353
|
+
### Granules
|
|
354
|
+
Utility functions for parsing granule information from a Cumulus message
|
|
355
|
+
|
|
356
|
+
**Example**
|
|
357
|
+
```js
|
|
358
|
+
const Granules = require('@cumulus/message/Granules');
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
* [Granules](#module_Granules)
|
|
362
|
+
* [getMessageGranules(message)](#exp_module_Granules--getMessageGranules) ⇒ <code>Array.<Object></code> \| <code>undefined</code> ⏏
|
|
363
|
+
* [messageHasGranules(message)](#exp_module_Granules--messageHasGranules) ⇒ <code>boolean</code> ⏏
|
|
364
|
+
* [getGranuleStatus(workflowStatus, granule)](#exp_module_Granules--getGranuleStatus) ⇒ <code>string</code> ⏏
|
|
365
|
+
* [getGranuleQueryFields(message)](#exp_module_Granules--getGranuleQueryFields) ⇒ <code>unknown</code> \| <code>undefined</code> ⏏
|
|
366
|
+
* [generateGranuleApiRecord(message)](#exp_module_Granules--generateGranuleApiRecord) ⇒ <code>Promise.<ApiGranule></code> ⏏
|
|
367
|
+
|
|
368
|
+
<a name="exp_module_Granules--getMessageGranules"></a>
|
|
369
|
+
|
|
370
|
+
#### getMessageGranules(message) ⇒ <code>Array.<Object></code> \| <code>undefined</code> ⏏
|
|
371
|
+
Get granules from payload?.granules of a workflow message.
|
|
372
|
+
|
|
373
|
+
**Kind**: Exported function
|
|
374
|
+
**Returns**: <code>Array.<Object></code> \| <code>undefined</code> - An array of granule objects, or
|
|
375
|
+
undefined if `message.payload.granules` is not set
|
|
376
|
+
|
|
377
|
+
| Param | Type | Description |
|
|
378
|
+
| --- | --- | --- |
|
|
379
|
+
| message | <code>MessageWithGranules</code> | A workflow message |
|
|
380
|
+
|
|
381
|
+
<a name="exp_module_Granules--messageHasGranules"></a>
|
|
382
|
+
|
|
383
|
+
#### messageHasGranules(message) ⇒ <code>boolean</code> ⏏
|
|
384
|
+
Determine if message has a granules object.
|
|
385
|
+
|
|
386
|
+
**Kind**: Exported function
|
|
387
|
+
**Returns**: <code>boolean</code> - true if message has a granules object
|
|
388
|
+
|
|
389
|
+
| Param | Type | Description |
|
|
390
|
+
| --- | --- | --- |
|
|
391
|
+
| message | <code>MessageWithOptionalGranules</code> | A workflow message object |
|
|
392
|
+
|
|
393
|
+
<a name="exp_module_Granules--getGranuleStatus"></a>
|
|
394
|
+
|
|
395
|
+
#### getGranuleStatus(workflowStatus, granule) ⇒ <code>string</code> ⏏
|
|
396
|
+
Determine the status of a granule.
|
|
397
|
+
|
|
398
|
+
**Kind**: Exported function
|
|
399
|
+
**Returns**: <code>string</code> - The granule status
|
|
400
|
+
|
|
401
|
+
| Param | Type | Description |
|
|
402
|
+
| --- | --- | --- |
|
|
403
|
+
| workflowStatus | <code>string</code> | The workflow status |
|
|
404
|
+
| granule | <code>MessageGranule</code> | A granule record conforming to the 'api' schema |
|
|
405
|
+
|
|
406
|
+
<a name="exp_module_Granules--getGranuleQueryFields"></a>
|
|
407
|
+
|
|
408
|
+
#### getGranuleQueryFields(message) ⇒ <code>unknown</code> \| <code>undefined</code> ⏏
|
|
409
|
+
Get the query fields of a granule, if any
|
|
410
|
+
|
|
411
|
+
**Kind**: Exported function
|
|
412
|
+
**Returns**: <code>unknown</code> \| <code>undefined</code> - The granule query fields, if any
|
|
413
|
+
|
|
414
|
+
| Param | Type | Description |
|
|
415
|
+
| --- | --- | --- |
|
|
416
|
+
| message | <code>MessageWithGranules</code> | A workflow message |
|
|
417
|
+
|
|
418
|
+
<a name="exp_module_Granules--generateGranuleApiRecord"></a>
|
|
419
|
+
|
|
420
|
+
#### generateGranuleApiRecord(message) ⇒ <code>Promise.<ApiGranule></code> ⏏
|
|
421
|
+
Generate an API granule record
|
|
422
|
+
|
|
423
|
+
**Kind**: Exported function
|
|
424
|
+
**Returns**: <code>Promise.<ApiGranule></code> - The granule API record
|
|
425
|
+
|
|
426
|
+
| Param | Type | Description |
|
|
427
|
+
| --- | --- | --- |
|
|
428
|
+
| message | <code>MessageWithGranules</code> | A workflow message |
|
|
324
429
|
|
|
325
430
|
<a name="module_Queue"></a>
|
|
326
431
|
|
|
@@ -378,19 +483,6 @@ Determine if there is a queue and queue execution limit in the message.
|
|
|
378
483
|
| --- | --- | --- |
|
|
379
484
|
| message | <code>MessageWithQueueInfo</code> | A workflow message object |
|
|
380
485
|
|
|
381
|
-
<a name="deconstructCollectionId"></a>
|
|
382
|
-
|
|
383
|
-
### deconstructCollectionId(collectionId) ⇒ <code>Object</code>
|
|
384
|
-
Returns the name and version of a collection based on
|
|
385
|
-
the collectionId used in elasticsearch indexing
|
|
386
|
-
|
|
387
|
-
**Kind**: global function
|
|
388
|
-
**Returns**: <code>Object</code> - name and version as object
|
|
389
|
-
|
|
390
|
-
| Param | Type | Description |
|
|
391
|
-
| --- | --- | --- |
|
|
392
|
-
| collectionId | <code>string</code> | collectionId used in elasticsearch index |
|
|
393
|
-
|
|
394
486
|
<a name="unwrapDeadLetterCumulusMessage"></a>
|
|
395
487
|
|
|
396
488
|
### unwrapDeadLetterCumulusMessage(messageBody) ⇒ <code>Object</code>
|
|
@@ -451,6 +543,18 @@ Falls back to overall execution input.
|
|
|
451
543
|
| inputCumulusMessage | <code>Object</code> | Workflow execution input message |
|
|
452
544
|
| getExecutionHistoryFunction | <code>function</code> | Testing override for mock/etc of StepFunctions.getExecutionHistory |
|
|
453
545
|
|
|
546
|
+
<a name="parseException"></a>
|
|
547
|
+
|
|
548
|
+
### parseException(exception) ⇒ <code>string</code>
|
|
549
|
+
Ensures that the exception is returned as an object
|
|
550
|
+
|
|
551
|
+
**Kind**: global function
|
|
552
|
+
**Returns**: <code>string</code> - an stringified exception
|
|
553
|
+
|
|
554
|
+
| Param | Type | Description |
|
|
555
|
+
| --- | --- | --- |
|
|
556
|
+
| exception | <code>Object</code> \| <code>undefined</code> | the exception |
|
|
557
|
+
|
|
454
558
|
|
|
455
559
|
## About Cumulus
|
|
456
560
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cumulus/message",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.1.0",
|
|
4
4
|
"description": "Utilities for building and parsing Cumulus messages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"GIBS",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"author": "Cumulus Authors",
|
|
39
39
|
"license": "Apache-2.0",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@cumulus/aws-client": "
|
|
42
|
-
"@cumulus/common": "
|
|
43
|
-
"@cumulus/errors": "
|
|
44
|
-
"@cumulus/logger": "
|
|
45
|
-
"@cumulus/types": "
|
|
41
|
+
"@cumulus/aws-client": "11.1.0",
|
|
42
|
+
"@cumulus/common": "11.1.0",
|
|
43
|
+
"@cumulus/errors": "11.1.0",
|
|
44
|
+
"@cumulus/logger": "11.1.0",
|
|
45
|
+
"@cumulus/types": "11.1.0",
|
|
46
46
|
"jsonpath-plus": "^3.0.0",
|
|
47
47
|
"lodash": "^4.17.21",
|
|
48
48
|
"uuid": "^8.2.0"
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/uuid": "^8.0.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "a846e319e143684ebc408e35f8b51cc1a7195391"
|
|
54
54
|
}
|
package/src/Collections.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
import { Message } from '@cumulus/types';
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
export const collectionIdSeparator = '___';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Utility functions for generating collection information or parsing collection information
|
|
@@ -36,6 +37,8 @@ export const constructCollectionId = (name: string, version: string) =>
|
|
|
36
37
|
*
|
|
37
38
|
* @param {string} collectionId - collectionId used in elasticsearch index
|
|
38
39
|
* @returns {Object} name and version as object
|
|
40
|
+
*
|
|
41
|
+
* @alias module:Collections
|
|
39
42
|
*/
|
|
40
43
|
export const deconstructCollectionId = (collectionId: string) => {
|
|
41
44
|
let name;
|
package/src/Executions.ts
CHANGED
|
@@ -11,9 +11,31 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import isString from 'lodash/isString';
|
|
14
|
+
import isNil from 'lodash/isNil';
|
|
15
|
+
import omitBy from 'lodash/omitBy';
|
|
16
|
+
|
|
14
17
|
import { Message } from '@cumulus/types';
|
|
18
|
+
import { ExecutionRecord } from '@cumulus/types/api/executions';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
getMessageAsyncOperationId,
|
|
22
|
+
} from './AsyncOperations';
|
|
23
|
+
import {
|
|
24
|
+
getCollectionIdFromMessage,
|
|
25
|
+
} from './Collections';
|
|
26
|
+
import {
|
|
27
|
+
getMetaStatus,
|
|
28
|
+
getMessageWorkflowTasks,
|
|
29
|
+
getMessageWorkflowStartTime,
|
|
30
|
+
getMessageWorkflowStopTime,
|
|
31
|
+
getMessageWorkflowName,
|
|
32
|
+
getWorkflowDuration,
|
|
33
|
+
} from './workflows';
|
|
34
|
+
import { parseException } from './utils';
|
|
15
35
|
|
|
16
|
-
|
|
36
|
+
interface MessageWithPayload extends Message.CumulusMessage {
|
|
37
|
+
payload: object
|
|
38
|
+
}
|
|
17
39
|
|
|
18
40
|
/**
|
|
19
41
|
* Build execution ARN from a state machine ARN and execution name
|
|
@@ -152,14 +174,14 @@ export const getMessageCumulusVersion = (
|
|
|
152
174
|
/**
|
|
153
175
|
* Get the workflow original payload, if any.
|
|
154
176
|
*
|
|
155
|
-
* @param {
|
|
177
|
+
* @param {MessageWithPayload} message - A workflow message object
|
|
156
178
|
* @returns {unknown|undefined} The workflow original payload
|
|
157
179
|
*
|
|
158
180
|
* @alias module:Executions
|
|
159
181
|
*/
|
|
160
182
|
export const getMessageExecutionOriginalPayload = (
|
|
161
|
-
message:
|
|
162
|
-
)
|
|
183
|
+
message: MessageWithPayload
|
|
184
|
+
) => {
|
|
163
185
|
const status = getMetaStatus(message);
|
|
164
186
|
return status === 'running' ? message.payload : undefined;
|
|
165
187
|
};
|
|
@@ -167,14 +189,62 @@ export const getMessageExecutionOriginalPayload = (
|
|
|
167
189
|
/**
|
|
168
190
|
* Get the workflow final payload, if any.
|
|
169
191
|
*
|
|
170
|
-
* @param {
|
|
192
|
+
* @param {MessageWithPayload} message - A workflow message object
|
|
171
193
|
* @returns {unknown|undefined} The workflow final payload
|
|
172
194
|
*
|
|
173
195
|
* @alias module:Executions
|
|
174
196
|
*/
|
|
175
197
|
export const getMessageExecutionFinalPayload = (
|
|
176
|
-
message:
|
|
177
|
-
)
|
|
198
|
+
message: MessageWithPayload
|
|
199
|
+
) => {
|
|
178
200
|
const status = getMetaStatus(message);
|
|
179
201
|
return status === 'running' ? undefined : message.payload;
|
|
180
202
|
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Generate an execution record for the API from the message.
|
|
206
|
+
*
|
|
207
|
+
* @param {MessageWithPayload} message - A workflow message object
|
|
208
|
+
* @param {string} [updatedAt] - Optional updated timestamp to apply to record
|
|
209
|
+
* @returns {ExecutionRecord} An execution API record
|
|
210
|
+
*
|
|
211
|
+
* @alias module:Executions
|
|
212
|
+
*/
|
|
213
|
+
export const generateExecutionApiRecordFromMessage = (
|
|
214
|
+
message: MessageWithPayload,
|
|
215
|
+
updatedAt = Date.now()
|
|
216
|
+
): ExecutionRecord => {
|
|
217
|
+
const arn = getMessageExecutionArn(message);
|
|
218
|
+
if (isNil(arn)) throw new Error('Unable to determine execution ARN from Cumulus message');
|
|
219
|
+
|
|
220
|
+
const status = getMetaStatus(message);
|
|
221
|
+
if (!status) throw new Error('Unable to determine status from Cumulus message');
|
|
222
|
+
|
|
223
|
+
const now = Date.now();
|
|
224
|
+
const workflowStartTime = getMessageWorkflowStartTime(message);
|
|
225
|
+
const workflowStopTime = getMessageWorkflowStopTime(message);
|
|
226
|
+
const collectionId = getCollectionIdFromMessage(message);
|
|
227
|
+
|
|
228
|
+
const record: ExecutionRecord = {
|
|
229
|
+
name: getMessageExecutionName(message),
|
|
230
|
+
cumulusVersion: getMessageCumulusVersion(message),
|
|
231
|
+
arn,
|
|
232
|
+
asyncOperationId: getMessageAsyncOperationId(message),
|
|
233
|
+
parentArn: getMessageExecutionParentArn(message),
|
|
234
|
+
execution: getExecutionUrlFromArn(arn),
|
|
235
|
+
tasks: getMessageWorkflowTasks(message),
|
|
236
|
+
error: parseException(message.exception),
|
|
237
|
+
type: getMessageWorkflowName(message),
|
|
238
|
+
collectionId,
|
|
239
|
+
status,
|
|
240
|
+
createdAt: workflowStartTime,
|
|
241
|
+
timestamp: now,
|
|
242
|
+
updatedAt,
|
|
243
|
+
originalPayload: getMessageExecutionOriginalPayload(message),
|
|
244
|
+
finalPayload: getMessageExecutionFinalPayload(message),
|
|
245
|
+
duration: getWorkflowDuration(workflowStartTime, workflowStopTime),
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const updated = <ExecutionRecord>omitBy(record, isNil);
|
|
249
|
+
return updated;
|
|
250
|
+
};
|