123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- '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
|