@cumulus/message
Version:
Utilities for building and parsing Cumulus messages
75 lines • 3.02 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWorkflowDuration = exports.getMessageWorkflowName = exports.getMessageWorkflowStopTime = exports.getMessageWorkflowStartTime = exports.getMessageWorkflowTasks = exports.getMetaStatus = void 0;
const isNil_1 = __importDefault(require("lodash/isNil"));
const errors_1 = require("@cumulus/errors");
/**
* Get the status of a workflow message, if any.
*
* @param {MessageWithOptionalStatus} message - A workflow message object
* @returns {Message.WorkflowStatus|undefined} The workflow status
*
* @alias module:workflows
*/
const getMetaStatus = (message) => message.meta?.status;
exports.getMetaStatus = getMetaStatus;
/**
* Get the workflow tasks in a workflow message, if any.
*
* @param {MessageWithOptionalWorkflowInfo} message - A workflow message object
* @returns {Object|undefined} A map of the workflow tasks
*
* @alias module:workflows
*/
const getMessageWorkflowTasks = (message) => message.meta?.workflow_tasks;
exports.getMessageWorkflowTasks = getMessageWorkflowTasks;
/**
* Get the workflow start time, if any.
*
* @param {MessageWithOptionalWorkflowInfo} message - A workflow message object
* @returns {number|undefined} The workflow start time, in milliseconds
*
* @alias module:workflows
*/
const getMessageWorkflowStartTime = (message) => {
if (!message.cumulus_meta.workflow_start_time) {
throw new errors_1.CumulusMessageError('getMessageWorkflowStartTime on a message without a workflow_start_time');
}
return message.cumulus_meta.workflow_start_time;
};
exports.getMessageWorkflowStartTime = getMessageWorkflowStartTime;
/**
* Get the workflow stop time, if any.
*
* @param {MessageWithOptionalWorkflowInfo} message - A workflow message object
* @returns {number|undefined} The workflow stop time, in milliseconds
*
* @alias module:workflows
*/
const getMessageWorkflowStopTime = (message) => message.cumulus_meta?.workflow_stop_time;
exports.getMessageWorkflowStopTime = getMessageWorkflowStopTime;
/**
* Get the workflow name, if any.
*
* @param {Message.CumulusMessage} message - A workflow message object
* @returns {string|undefined} The workflow name
*
* @alias module:workflows
*/
const getMessageWorkflowName = (message) => message.meta?.workflow_name;
exports.getMessageWorkflowName = getMessageWorkflowName;
/**
* Get the workflow duration.
*
* @param {number} startTime - Workflow start time (as timestamp in ms)
* @param {number} [stopTime] - Time to use for measuring duration (as timestamp in ms)
* @returns {number} The workflow duration (in seconds)
*
* @alias module:workflows
*/
const getWorkflowDuration = (startTime, stopTime) => ((0, isNil_1.default)(stopTime) ? 0 : (stopTime - startTime) / 1000);
exports.getWorkflowDuration = getWorkflowDuration;
//# sourceMappingURL=workflows.js.map
;