UNPKG

@awhere/api

Version:

The awesome aWhere API for JavaScript.

179 lines 6.2 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var IdentityMixin_1 = __importDefault(require("../IdentityMixin")); var TaskWatcher_1 = require("./TaskWatcher"); var Task = /** @class */ (function (_super) { __extends(Task, _super); function Task(props) { var _this = _super.call(this) || this; _this.basePath = '/job'; _this._id = props.id; _this._name = props.name; _this._progress = props.progress; _this._delay = props.delay; _this._timestamp = props.timestamp; _this._attemptsMade = props.attemptsMade; _this._stacktrace = props.stacktrace; _this._returnvalue = props.returnvalue; _this._finishedOn = props.finishedOn; _this._processedOn = props.processedOn; _this._user = props.user; return _this; } // private static generateId = uuid('awhere.core.task'); Task.watch = function (jobId) { var _this = this; return new Promise(function (resolve, reject) { var namespace = '/task-manager'; _this.socket.open(); _this.socket.emit('call', "sub:".concat(namespace), jobId, function (err) { err ? reject(err) : resolve(new TaskWatcher_1.TaskWatcher(_this.socket, jobId)); }); }); }; Task.find = function (findOptions) { if (typeof findOptions === 'string') { throw new Error('invalid findOptions'); } return this.request .get("".concat(this.basePath)) .then(function (res) { return res.data; }) .then(function (res) { return res.data; }); }; Task.fromId = function (id) { return this.request .get("".concat(this.basePath, "/").concat(id)) .then(function (res) { return res.data; }) .then(function (res) { return res.data; }) .then(function (data) { return new Task(data); }); }; Task.fromJSON = function (props) { return new Task(props); }; Object.defineProperty(Task.prototype, "id", { get: function () { return this._id; }, enumerable: false, configurable: true }); Object.defineProperty(Task.prototype, "name", { get: function () { return this._name; }, enumerable: false, configurable: true }); Object.defineProperty(Task.prototype, "progress", { get: function () { return this._progress; }, enumerable: false, configurable: true }); Object.defineProperty(Task.prototype, "delay", { get: function () { return this._delay; }, enumerable: false, configurable: true }); Object.defineProperty(Task.prototype, "timestamp", { get: function () { return this._timestamp; }, enumerable: false, configurable: true }); Object.defineProperty(Task.prototype, "attemptsMade", { get: function () { return this._attemptsMade; }, enumerable: false, configurable: true }); Object.defineProperty(Task.prototype, "stacktrace", { get: function () { return this._stacktrace; }, enumerable: false, configurable: true }); Object.defineProperty(Task.prototype, "returnvalue", { get: function () { return this._returnvalue; }, enumerable: false, configurable: true }); Object.defineProperty(Task.prototype, "finishedOn", { get: function () { return this._finishedOn; }, enumerable: false, configurable: true }); Object.defineProperty(Task.prototype, "processedOn", { get: function () { return this._processedOn; }, enumerable: false, configurable: true }); Object.defineProperty(Task.prototype, "user", { get: function () { return this._user; }, enumerable: false, configurable: true }); Task.prototype.toJSON = function () { return { id: this.id, name: this.name, progress: this.progress, delay: this.delay, timestamp: this.timestamp, attemptsMade: this.attemptsMade, stacktrace: this.stacktrace, returnvalue: this.returnvalue, finishedOn: this.finishedOn, processedOn: this.processedOn, user: this.user, }; }; Task.prototype.getProgress = function () { return this.request .get("".concat(this.basePath, "/").concat(this._id, "/progress")) .then(function (res) { return res.data; }) .then(function (res) { return res.data; }); }; Task.prototype.getLogs = function () { return this.request .get("".concat(this.basePath, "/").concat(this._id, "/logs")) .then(function (res) { return res.data; }) .then(function (res) { return res.data; }); }; Task.basePath = '/job'; return Task; }(IdentityMixin_1.default)); exports.default = Task; //# sourceMappingURL=Task.js.map