'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Business Analytics (C) Copyright IBM Corp. 2019 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ /** * @class RenderTaskExecInfo * @hideconstructor * @classdesc Save the info of a render task */ define([], function () { var RenderTaskExecInfo = function () { /** * @public * @description initializes a task info by setting the start time */ function RenderTaskExecInfo(options) { _classCallCheck(this, RenderTaskExecInfo); this._id = options.id; this._startTime = Date.now(); this._endTime = undefined; this._error = undefined; this._data = new Map([]); this._requestTimeInfo = []; } /** * @public * @function RenderTaskExecInfo#getId * @description returns the task id */ RenderTaskExecInfo.prototype.getId = function getId() { return this._id; }; /** * @public * @function RenderTaskExecInfo#setEndTime * @description set the end time of the task execution */ RenderTaskExecInfo.prototype.setEndTime = function setEndTime() { this._endTime = Date.now(); }; /** * @public * @function RenderTaskExecInfo#setError * @description set the error attached to the task execution * @param {Error} - error instance from commmon see {@link Error} */ RenderTaskExecInfo.prototype.setError = function setError(error) { this._error = error; }; /** * @public * @function getDuration * @description get the duration calculation from the task execution * @returns {number} The duration in milliseconds */ RenderTaskExecInfo.prototype.getDuration = function getDuration() { return this._endTime ? this._endTime - this._startTime : Date.now() - this._startTime; }; /** * @public * @function getRequestDurations * @description gets the durations of all the requests that occured in the task * @returns {number[]} array of request durations */ RenderTaskExecInfo.prototype.getRequestDurations = function getRequestDurations() { var durations = []; this._requestTimeInfo.forEach(function (timeInfo) { if (typeof timeInfo === 'string') { durations.push(parseInt(timeInfo.replace(/^.*;/, '').trim().replace(/elapsed=/, ''), 10)); } else { durations.push(NaN); } }); return durations; }; /** * @public * @function addRequestTimeInfo * @description adds a request info; add NaN if the timeInfo is not a valid formatted string * @params {string} timeInfo - string of the following format: path;start=0;end=2;elapsed=2 */ RenderTaskExecInfo.prototype.addRequestTimeInfo = function addRequestTimeInfo(requestTimeInfo) { this._requestTimeInfo.push(requestTimeInfo); }; /** * @public * @function RenderTaskExecInfo#toJson * @description generates the json representing the task exec info * @returns {Object} json object */ RenderTaskExecInfo.prototype.toJSON = function toJSON() { var json = { 'task id': this._id, 'task start time': this._startTime, 'task end time': this._endTime, 'duration': this.getDuration(), 'error': this._error ? this._error.toJson() : undefined, 'requestTimes': this.getRequestDurations() }; this._data.forEach(function (value, key) { if (value && typeof value.toJSON === 'function') { json[key] = value.toJSON(); } else { json[key] = value; } }); return json; }; /** * @public * @function RenderTaskExecInfo#setData * @description set Data */ RenderTaskExecInfo.prototype.setData = function setData(key, value) { if (typeof key !== 'string') { throw new Error('Invalid or undefined key: [' + key + ']'); } this._data.set(key, value); }; RenderTaskExecInfo.prototype.getData = function getData(key) { return this._data.get(key); }; return RenderTaskExecInfo; }(); return RenderTaskExecInfo; }); //# sourceMappingURL=RenderTaskExecInfo.js.map