Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

long-long-job

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

long-long-job - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

8

dist/actions/Action.js

@@ -7,10 +7,6 @@ "use strict";

var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Action = function Action(state) {
(0, _classCallCheck3.default)(this, Action);
_classCallCheck(this, Action);

@@ -17,0 +13,0 @@ this.state = state;

@@ -7,27 +7,21 @@ 'use strict';

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _Action2 = require('./Action');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _Action3 = _interopRequireDefault(_Action2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _inherits2 = require('babel-runtime/helpers/inherits');
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
var _inherits3 = _interopRequireDefault(_inherits2);
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _Action2 = require('./Action');
var _Action3 = _interopRequireDefault(_Action2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Goto = function (_Action) {
(0, _inherits3.default)(Goto, _Action);
_inherits(Goto, _Action);
function Goto(label, state) {
(0, _classCallCheck3.default)(this, Goto);
_classCallCheck(this, Goto);
var _this = (0, _possibleConstructorReturn3.default)(this, (Goto.__proto__ || Object.getPrototypeOf(Goto)).call(this, state));
var _this = _possibleConstructorReturn(this, (Goto.__proto__ || Object.getPrototypeOf(Goto)).call(this, state));

@@ -34,0 +28,0 @@ _this.label = label;

@@ -7,26 +7,21 @@ 'use strict';

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _Action2 = require('./Action');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _Action3 = _interopRequireDefault(_Action2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _inherits2 = require('babel-runtime/helpers/inherits');
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
var _inherits3 = _interopRequireDefault(_inherits2);
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _Action2 = require('./Action');
var _Action3 = _interopRequireDefault(_Action2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Next = function (_Action) {
(0, _inherits3.default)(Next, _Action);
_inherits(Next, _Action);
function Next() {
(0, _classCallCheck3.default)(this, Next);
return (0, _possibleConstructorReturn3.default)(this, (Next.__proto__ || Object.getPrototypeOf(Next)).apply(this, arguments));
_classCallCheck(this, Next);
return _possibleConstructorReturn(this, (Next.__proto__ || Object.getPrototypeOf(Next)).apply(this, arguments));
}

@@ -33,0 +28,0 @@

@@ -7,26 +7,21 @@ 'use strict';

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _Action2 = require('./Action');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _Action3 = _interopRequireDefault(_Action2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _inherits2 = require('babel-runtime/helpers/inherits');
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
var _inherits3 = _interopRequireDefault(_inherits2);
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _Action2 = require('./Action');
var _Action3 = _interopRequireDefault(_Action2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Repeat = function (_Action) {
(0, _inherits3.default)(Repeat, _Action);
_inherits(Repeat, _Action);
function Repeat() {
(0, _classCallCheck3.default)(this, Repeat);
return (0, _possibleConstructorReturn3.default)(this, (Repeat.__proto__ || Object.getPrototypeOf(Repeat)).apply(this, arguments));
_classCallCheck(this, Repeat);
return _possibleConstructorReturn(this, (Repeat.__proto__ || Object.getPrototypeOf(Repeat)).apply(this, arguments));
}

@@ -33,0 +28,0 @@

@@ -7,10 +7,6 @@ "use strict";

var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Label = function Label(label) {
(0, _classCallCheck3.default)(this, Label);
_classCallCheck(this, Label);

@@ -17,0 +13,0 @@ this.label = label;

@@ -7,18 +7,8 @@ 'use strict';

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _regenerator = require('babel-runtime/regenerator');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _regenerator2 = _interopRequireDefault(_regenerator);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _events = require('events');

@@ -34,10 +24,18 @@

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
exports.default = function (stateService) {
return function (_EventEmitter) {
(0, _inherits3.default)(LongLongJob, _EventEmitter);
_inherits(LongLongJob, _EventEmitter);
function LongLongJob(id, tasks) {
(0, _classCallCheck3.default)(this, LongLongJob);
_classCallCheck(this, LongLongJob);
var _this = (0, _possibleConstructorReturn3.default)(this, (LongLongJob.__proto__ || Object.getPrototypeOf(LongLongJob)).call(this));
var _this = _possibleConstructorReturn(this, (LongLongJob.__proto__ || Object.getPrototypeOf(LongLongJob)).call(this));

@@ -50,60 +48,149 @@ _this.id = id;

(0, _createClass3.default)(LongLongJob, [{
_createClass(LongLongJob, [{
key: 'start',
value: async function start(initialState) {
if (this.isRunning) {
throw new Error('Already started');
}
value: function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(initialState) {
var _groupTaskUnits, labels, tasks, _ref2, cursor, state, action;
this.isRunning = true;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!this.isRunning) {
_context.next = 2;
break;
}
var _groupTaskUnits = (0, _util.groupTaskUnits)(this.tasks),
labels = _groupTaskUnits.labels,
tasks = _groupTaskUnits.tasks;
throw new Error('Already started');
if (await this.hasStoredState()) {
this.emit('resume');
} else {
this.emit('start');
}
case 2:
var _ref = await this.getTaskState(initialState),
cursor = _ref.cursor,
state = _ref.state;
this.isRunning = true;
while (tasks[cursor] !== undefined) {
if (!this.isRunning) {
throw new Error('Job terminated');
}
_groupTaskUnits = (0, _util.groupTaskUnits)(this.tasks), labels = _groupTaskUnits.labels, tasks = _groupTaskUnits.tasks;
_context.next = 6;
return this.hasStoredState();
this.emit('task', cursor, state);
case 6:
if (!_context.sent) {
_context.next = 10;
break;
}
var action = await tasks[cursor](state);
this.emit('resume');
_context.next = 11;
break;
if (action instanceof _actions.Next) {
cursor += 1;
} else if (action instanceof _actions.Repeat) {
/* Blank */
} else if (action instanceof _actions.Goto) {
if (labels[action.label] === undefined) {
throw new Error('Label ' + action.label + ' does not exist');
}
cursor = labels[action.label];
} else {
throw new Error('Task should return an action');
}
case 10:
this.emit('start');
state = action.state;
case 11:
_context.next = 13;
return this.getTaskState(initialState);
await stateService.setState(this.id, { cursor: cursor, state: state });
}
case 13:
_ref2 = _context.sent;
cursor = _ref2.cursor;
state = _ref2.state;
this.emit('done', state);
case 16:
if (!(tasks[cursor] !== undefined)) {
_context.next = 42;
break;
}
await this.clearStoredState();
if (this.isRunning) {
_context.next = 19;
break;
}
this.isRunning = false;
throw new Error('Job terminated');
return state;
}
case 19:
this.emit('task', cursor, state);
_context.next = 22;
return tasks[cursor](state);
case 22:
action = _context.sent;
if (!(action instanceof _actions.Next)) {
_context.next = 27;
break;
}
cursor += 1;
_context.next = 37;
break;
case 27:
if (!(action instanceof _actions.Repeat)) {
_context.next = 30;
break;
}
_context.next = 37;
break;
case 30:
if (!(action instanceof _actions.Goto)) {
_context.next = 36;
break;
}
if (!(labels[action.label] === undefined)) {
_context.next = 33;
break;
}
throw new Error('Label ' + action.label + ' does not exist');
case 33:
cursor = labels[action.label];
_context.next = 37;
break;
case 36:
throw new Error('Task should return an action');
case 37:
state = action.state;
_context.next = 40;
return stateService.setState(this.id, { cursor: cursor, state: state });
case 40:
_context.next = 16;
break;
case 42:
this.emit('done', state);
_context.next = 45;
return this.clearStoredState();
case 45:
this.isRunning = false;
return _context.abrupt('return', state);
case 47:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
function start(_x) {
return _ref.apply(this, arguments);
}
return start;
}()
}, {

@@ -116,22 +203,92 @@ key: 'terminate',

key: 'getTaskState',
value: async function getTaskState(initialState) {
var taskState = await stateService.getState(this.id);
if (taskState === null || taskState === undefined) {
return { cursor: 0, state: initialState };
value: function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2(initialState) {
var taskState;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return stateService.getState(this.id);
case 2:
taskState = _context2.sent;
if (!(taskState === null || taskState === undefined)) {
_context2.next = 5;
break;
}
return _context2.abrupt('return', { cursor: 0, state: initialState });
case 5:
return _context2.abrupt('return', taskState);
case 6:
case 'end':
return _context2.stop();
}
}
}, _callee2, this);
}));
function getTaskState(_x2) {
return _ref3.apply(this, arguments);
}
return taskState;
}
return getTaskState;
}()
}, {
key: 'hasStoredState',
value: async function hasStoredState() {
return stateService.hasState(this.id);
}
value: function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee3() {
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
return _context3.abrupt('return', stateService.hasState(this.id));
case 1:
case 'end':
return _context3.stop();
}
}
}, _callee3, this);
}));
function hasStoredState() {
return _ref4.apply(this, arguments);
}
return hasStoredState;
}()
}, {
key: 'clearStoredState',
value: async function clearStoredState() {
await stateService.clean(this.id);
}
value: function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee4() {
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return stateService.clean(this.id);
case 2:
case 'end':
return _context4.stop();
}
}
}, _callee4, this);
}));
function clearStoredState() {
return _ref5.apply(this, arguments);
}
return clearStoredState;
}()
}]);
return LongLongJob;
}(_events2.default);
};
{
"name": "long-long-job",
"version": "0.1.3",
"version": "0.1.4",
"description": "Library for execution of long jobs with resume support.",

@@ -15,8 +15,4 @@ "main": "dist/index.js",

"babel-jest": "~21.2.0",
"babel-plugin-transform-async-to-generator": "~6.24.1",
"babel-plugin-transform-es2015-modules-commonjs": "~6.26.0",
"babel-plugin-transform-flow-strip-types": "~6.22.0",
"babel-plugin-transform-runtime": "~6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-3": "~6.24.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-preset-react-app": "^3.1.1",
"coveralls": "^3.0.0",

@@ -44,3 +40,3 @@ "eslint": "~4.10.0",

"prebuild": "npm run clean",
"build": "babel src -d dist",
"build": "NODE_ENV=production babel src -d dist",
"build:watch": "babel --watch src/**.js -d dist",

@@ -47,0 +43,0 @@ "typed:install": "flow-typed install --skip",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc