@rango-dev/queue-manager-core 0.1.15-next.4 → 0.1.15-next.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -8
- package/dist/index.js.map +7 -0
- package/dist/manager.d.ts +212 -212
- package/dist/manager.d.ts.map +1 -1
- package/dist/persistor.d.ts +19 -19
- package/dist/persistor.d.ts.map +1 -1
- package/dist/queue.d.ts +181 -181
- package/dist/queue.d.ts.map +1 -1
- package/dist/types.d.ts +22 -22
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -6
- package/dist/queue-manager-core.cjs.development.js +0 -1500
- package/dist/queue-manager-core.cjs.development.js.map +0 -1
- package/dist/queue-manager-core.cjs.production.min.js +0 -2
- package/dist/queue-manager-core.cjs.production.min.js.map +0 -1
- package/dist/queue-manager-core.esm.js +0 -1494
- package/dist/queue-manager-core.esm.js.map +0 -1
|
@@ -1,1494 +0,0 @@
|
|
|
1
|
-
import { openDB } from 'idb';
|
|
2
|
-
import { v4 } from 'uuid';
|
|
3
|
-
|
|
4
|
-
function _regeneratorRuntime() {
|
|
5
|
-
_regeneratorRuntime = function () {
|
|
6
|
-
return exports;
|
|
7
|
-
};
|
|
8
|
-
var exports = {},
|
|
9
|
-
Op = Object.prototype,
|
|
10
|
-
hasOwn = Op.hasOwnProperty,
|
|
11
|
-
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
|
12
|
-
obj[key] = desc.value;
|
|
13
|
-
},
|
|
14
|
-
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
15
|
-
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
16
|
-
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
17
|
-
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
18
|
-
function define(obj, key, value) {
|
|
19
|
-
return Object.defineProperty(obj, key, {
|
|
20
|
-
value: value,
|
|
21
|
-
enumerable: !0,
|
|
22
|
-
configurable: !0,
|
|
23
|
-
writable: !0
|
|
24
|
-
}), obj[key];
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
define({}, "");
|
|
28
|
-
} catch (err) {
|
|
29
|
-
define = function (obj, key, value) {
|
|
30
|
-
return obj[key] = value;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
34
|
-
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
35
|
-
generator = Object.create(protoGenerator.prototype),
|
|
36
|
-
context = new Context(tryLocsList || []);
|
|
37
|
-
return defineProperty(generator, "_invoke", {
|
|
38
|
-
value: makeInvokeMethod(innerFn, self, context)
|
|
39
|
-
}), generator;
|
|
40
|
-
}
|
|
41
|
-
function tryCatch(fn, obj, arg) {
|
|
42
|
-
try {
|
|
43
|
-
return {
|
|
44
|
-
type: "normal",
|
|
45
|
-
arg: fn.call(obj, arg)
|
|
46
|
-
};
|
|
47
|
-
} catch (err) {
|
|
48
|
-
return {
|
|
49
|
-
type: "throw",
|
|
50
|
-
arg: err
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.wrap = wrap;
|
|
55
|
-
var ContinueSentinel = {};
|
|
56
|
-
function Generator() {}
|
|
57
|
-
function GeneratorFunction() {}
|
|
58
|
-
function GeneratorFunctionPrototype() {}
|
|
59
|
-
var IteratorPrototype = {};
|
|
60
|
-
define(IteratorPrototype, iteratorSymbol, function () {
|
|
61
|
-
return this;
|
|
62
|
-
});
|
|
63
|
-
var getProto = Object.getPrototypeOf,
|
|
64
|
-
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
65
|
-
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
66
|
-
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
67
|
-
function defineIteratorMethods(prototype) {
|
|
68
|
-
["next", "throw", "return"].forEach(function (method) {
|
|
69
|
-
define(prototype, method, function (arg) {
|
|
70
|
-
return this._invoke(method, arg);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
75
|
-
function invoke(method, arg, resolve, reject) {
|
|
76
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
77
|
-
if ("throw" !== record.type) {
|
|
78
|
-
var result = record.arg,
|
|
79
|
-
value = result.value;
|
|
80
|
-
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
81
|
-
invoke("next", value, resolve, reject);
|
|
82
|
-
}, function (err) {
|
|
83
|
-
invoke("throw", err, resolve, reject);
|
|
84
|
-
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
85
|
-
result.value = unwrapped, resolve(result);
|
|
86
|
-
}, function (error) {
|
|
87
|
-
return invoke("throw", error, resolve, reject);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
reject(record.arg);
|
|
91
|
-
}
|
|
92
|
-
var previousPromise;
|
|
93
|
-
defineProperty(this, "_invoke", {
|
|
94
|
-
value: function (method, arg) {
|
|
95
|
-
function callInvokeWithMethodAndArg() {
|
|
96
|
-
return new PromiseImpl(function (resolve, reject) {
|
|
97
|
-
invoke(method, arg, resolve, reject);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
function makeInvokeMethod(innerFn, self, context) {
|
|
105
|
-
var state = "suspendedStart";
|
|
106
|
-
return function (method, arg) {
|
|
107
|
-
if ("executing" === state) throw new Error("Generator is already running");
|
|
108
|
-
if ("completed" === state) {
|
|
109
|
-
if ("throw" === method) throw arg;
|
|
110
|
-
return doneResult();
|
|
111
|
-
}
|
|
112
|
-
for (context.method = method, context.arg = arg;;) {
|
|
113
|
-
var delegate = context.delegate;
|
|
114
|
-
if (delegate) {
|
|
115
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
116
|
-
if (delegateResult) {
|
|
117
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
118
|
-
return delegateResult;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
122
|
-
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
123
|
-
context.dispatchException(context.arg);
|
|
124
|
-
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
125
|
-
state = "executing";
|
|
126
|
-
var record = tryCatch(innerFn, self, context);
|
|
127
|
-
if ("normal" === record.type) {
|
|
128
|
-
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
129
|
-
return {
|
|
130
|
-
value: record.arg,
|
|
131
|
-
done: context.done
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
139
|
-
var methodName = context.method,
|
|
140
|
-
method = delegate.iterator[methodName];
|
|
141
|
-
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
142
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
143
|
-
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
144
|
-
var info = record.arg;
|
|
145
|
-
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
146
|
-
}
|
|
147
|
-
function pushTryEntry(locs) {
|
|
148
|
-
var entry = {
|
|
149
|
-
tryLoc: locs[0]
|
|
150
|
-
};
|
|
151
|
-
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
152
|
-
}
|
|
153
|
-
function resetTryEntry(entry) {
|
|
154
|
-
var record = entry.completion || {};
|
|
155
|
-
record.type = "normal", delete record.arg, entry.completion = record;
|
|
156
|
-
}
|
|
157
|
-
function Context(tryLocsList) {
|
|
158
|
-
this.tryEntries = [{
|
|
159
|
-
tryLoc: "root"
|
|
160
|
-
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
161
|
-
}
|
|
162
|
-
function values(iterable) {
|
|
163
|
-
if (iterable) {
|
|
164
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
165
|
-
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
166
|
-
if ("function" == typeof iterable.next) return iterable;
|
|
167
|
-
if (!isNaN(iterable.length)) {
|
|
168
|
-
var i = -1,
|
|
169
|
-
next = function next() {
|
|
170
|
-
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
171
|
-
return next.value = undefined, next.done = !0, next;
|
|
172
|
-
};
|
|
173
|
-
return next.next = next;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
next: doneResult
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
function doneResult() {
|
|
181
|
-
return {
|
|
182
|
-
value: undefined,
|
|
183
|
-
done: !0
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
|
|
187
|
-
value: GeneratorFunctionPrototype,
|
|
188
|
-
configurable: !0
|
|
189
|
-
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
|
190
|
-
value: GeneratorFunction,
|
|
191
|
-
configurable: !0
|
|
192
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
193
|
-
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
194
|
-
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
195
|
-
}, exports.mark = function (genFun) {
|
|
196
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
197
|
-
}, exports.awrap = function (arg) {
|
|
198
|
-
return {
|
|
199
|
-
__await: arg
|
|
200
|
-
};
|
|
201
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
202
|
-
return this;
|
|
203
|
-
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
204
|
-
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
205
|
-
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
206
|
-
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
207
|
-
return result.done ? result.value : iter.next();
|
|
208
|
-
});
|
|
209
|
-
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
|
210
|
-
return this;
|
|
211
|
-
}), define(Gp, "toString", function () {
|
|
212
|
-
return "[object Generator]";
|
|
213
|
-
}), exports.keys = function (val) {
|
|
214
|
-
var object = Object(val),
|
|
215
|
-
keys = [];
|
|
216
|
-
for (var key in object) keys.push(key);
|
|
217
|
-
return keys.reverse(), function next() {
|
|
218
|
-
for (; keys.length;) {
|
|
219
|
-
var key = keys.pop();
|
|
220
|
-
if (key in object) return next.value = key, next.done = !1, next;
|
|
221
|
-
}
|
|
222
|
-
return next.done = !0, next;
|
|
223
|
-
};
|
|
224
|
-
}, exports.values = values, Context.prototype = {
|
|
225
|
-
constructor: Context,
|
|
226
|
-
reset: function (skipTempReset) {
|
|
227
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
228
|
-
},
|
|
229
|
-
stop: function () {
|
|
230
|
-
this.done = !0;
|
|
231
|
-
var rootRecord = this.tryEntries[0].completion;
|
|
232
|
-
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
233
|
-
return this.rval;
|
|
234
|
-
},
|
|
235
|
-
dispatchException: function (exception) {
|
|
236
|
-
if (this.done) throw exception;
|
|
237
|
-
var context = this;
|
|
238
|
-
function handle(loc, caught) {
|
|
239
|
-
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
240
|
-
}
|
|
241
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
242
|
-
var entry = this.tryEntries[i],
|
|
243
|
-
record = entry.completion;
|
|
244
|
-
if ("root" === entry.tryLoc) return handle("end");
|
|
245
|
-
if (entry.tryLoc <= this.prev) {
|
|
246
|
-
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
247
|
-
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
248
|
-
if (hasCatch && hasFinally) {
|
|
249
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
250
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
251
|
-
} else if (hasCatch) {
|
|
252
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
253
|
-
} else {
|
|
254
|
-
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
255
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
abrupt: function (type, arg) {
|
|
261
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
262
|
-
var entry = this.tryEntries[i];
|
|
263
|
-
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
264
|
-
var finallyEntry = entry;
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
|
269
|
-
var record = finallyEntry ? finallyEntry.completion : {};
|
|
270
|
-
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
|
271
|
-
},
|
|
272
|
-
complete: function (record, afterLoc) {
|
|
273
|
-
if ("throw" === record.type) throw record.arg;
|
|
274
|
-
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
|
|
275
|
-
},
|
|
276
|
-
finish: function (finallyLoc) {
|
|
277
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
278
|
-
var entry = this.tryEntries[i];
|
|
279
|
-
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
|
280
|
-
}
|
|
281
|
-
},
|
|
282
|
-
catch: function (tryLoc) {
|
|
283
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
284
|
-
var entry = this.tryEntries[i];
|
|
285
|
-
if (entry.tryLoc === tryLoc) {
|
|
286
|
-
var record = entry.completion;
|
|
287
|
-
if ("throw" === record.type) {
|
|
288
|
-
var thrown = record.arg;
|
|
289
|
-
resetTryEntry(entry);
|
|
290
|
-
}
|
|
291
|
-
return thrown;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
throw new Error("illegal catch attempt");
|
|
295
|
-
},
|
|
296
|
-
delegateYield: function (iterable, resultName, nextLoc) {
|
|
297
|
-
return this.delegate = {
|
|
298
|
-
iterator: values(iterable),
|
|
299
|
-
resultName: resultName,
|
|
300
|
-
nextLoc: nextLoc
|
|
301
|
-
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
302
|
-
}
|
|
303
|
-
}, exports;
|
|
304
|
-
}
|
|
305
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
306
|
-
try {
|
|
307
|
-
var info = gen[key](arg);
|
|
308
|
-
var value = info.value;
|
|
309
|
-
} catch (error) {
|
|
310
|
-
reject(error);
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
if (info.done) {
|
|
314
|
-
resolve(value);
|
|
315
|
-
} else {
|
|
316
|
-
Promise.resolve(value).then(_next, _throw);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
function _asyncToGenerator(fn) {
|
|
320
|
-
return function () {
|
|
321
|
-
var self = this,
|
|
322
|
-
args = arguments;
|
|
323
|
-
return new Promise(function (resolve, reject) {
|
|
324
|
-
var gen = fn.apply(self, args);
|
|
325
|
-
function _next(value) {
|
|
326
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
327
|
-
}
|
|
328
|
-
function _throw(err) {
|
|
329
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
330
|
-
}
|
|
331
|
-
_next(undefined);
|
|
332
|
-
});
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
function _extends() {
|
|
336
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
337
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
338
|
-
var source = arguments[i];
|
|
339
|
-
for (var key in source) {
|
|
340
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
341
|
-
target[key] = source[key];
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
return target;
|
|
346
|
-
};
|
|
347
|
-
return _extends.apply(this, arguments);
|
|
348
|
-
}
|
|
349
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
350
|
-
if (!o) return;
|
|
351
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
352
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
353
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
354
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
355
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
356
|
-
}
|
|
357
|
-
function _arrayLikeToArray(arr, len) {
|
|
358
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
359
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
360
|
-
return arr2;
|
|
361
|
-
}
|
|
362
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
363
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
364
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
365
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
366
|
-
if (it) o = it;
|
|
367
|
-
var i = 0;
|
|
368
|
-
return function () {
|
|
369
|
-
if (i >= o.length) return {
|
|
370
|
-
done: true
|
|
371
|
-
};
|
|
372
|
-
return {
|
|
373
|
-
done: false,
|
|
374
|
-
value: o[i++]
|
|
375
|
-
};
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
var DB_NAME = 'queues-manager';
|
|
382
|
-
var OBJECT_STORE_NAME = 'queues';
|
|
383
|
-
var VERSION = 1;
|
|
384
|
-
var Persistor = /*#__PURE__*/function () {
|
|
385
|
-
function Persistor() {
|
|
386
|
-
this.db = openDB(DB_NAME, VERSION, {
|
|
387
|
-
upgrade: function upgrade(db) {
|
|
388
|
-
db.createObjectStore(OBJECT_STORE_NAME, {
|
|
389
|
-
keyPath: 'id'
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
var _proto = Persistor.prototype;
|
|
395
|
-
_proto.insertQueue = /*#__PURE__*/function () {
|
|
396
|
-
var _insertQueue = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(queue) {
|
|
397
|
-
var db, queueRecord;
|
|
398
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
399
|
-
while (1) switch (_context.prev = _context.next) {
|
|
400
|
-
case 0:
|
|
401
|
-
_context.next = 2;
|
|
402
|
-
return this.db;
|
|
403
|
-
case 2:
|
|
404
|
-
db = _context.sent;
|
|
405
|
-
_context.next = 5;
|
|
406
|
-
return db.get(OBJECT_STORE_NAME, queue.id);
|
|
407
|
-
case 5:
|
|
408
|
-
queueRecord = _context.sent;
|
|
409
|
-
if (!queueRecord) {
|
|
410
|
-
_context.next = 9;
|
|
411
|
-
break;
|
|
412
|
-
}
|
|
413
|
-
_context.next = 11;
|
|
414
|
-
break;
|
|
415
|
-
case 9:
|
|
416
|
-
_context.next = 11;
|
|
417
|
-
return db.add(OBJECT_STORE_NAME, queue);
|
|
418
|
-
case 11:
|
|
419
|
-
case "end":
|
|
420
|
-
return _context.stop();
|
|
421
|
-
}
|
|
422
|
-
}, _callee, this);
|
|
423
|
-
}));
|
|
424
|
-
function insertQueue(_x) {
|
|
425
|
-
return _insertQueue.apply(this, arguments);
|
|
426
|
-
}
|
|
427
|
-
return insertQueue;
|
|
428
|
-
}();
|
|
429
|
-
_proto.updateQueue = /*#__PURE__*/function () {
|
|
430
|
-
var _updateQueue = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(id, queue) {
|
|
431
|
-
var db, currentRecord, updatedRecord;
|
|
432
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
433
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
434
|
-
case 0:
|
|
435
|
-
_context2.next = 2;
|
|
436
|
-
return this.db;
|
|
437
|
-
case 2:
|
|
438
|
-
db = _context2.sent;
|
|
439
|
-
_context2.next = 5;
|
|
440
|
-
return db.get(OBJECT_STORE_NAME, id);
|
|
441
|
-
case 5:
|
|
442
|
-
currentRecord = _context2.sent;
|
|
443
|
-
if (currentRecord) {
|
|
444
|
-
_context2.next = 8;
|
|
445
|
-
break;
|
|
446
|
-
}
|
|
447
|
-
return _context2.abrupt("return");
|
|
448
|
-
case 8:
|
|
449
|
-
updatedRecord = _extends({}, currentRecord, queue);
|
|
450
|
-
_context2.next = 11;
|
|
451
|
-
return db.put(OBJECT_STORE_NAME, updatedRecord);
|
|
452
|
-
case 11:
|
|
453
|
-
case "end":
|
|
454
|
-
return _context2.stop();
|
|
455
|
-
}
|
|
456
|
-
}, _callee2, this);
|
|
457
|
-
}));
|
|
458
|
-
function updateQueue(_x2, _x3) {
|
|
459
|
-
return _updateQueue.apply(this, arguments);
|
|
460
|
-
}
|
|
461
|
-
return updateQueue;
|
|
462
|
-
}();
|
|
463
|
-
_proto.getAll = /*#__PURE__*/function () {
|
|
464
|
-
var _getAll = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
465
|
-
var db, results;
|
|
466
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
467
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
468
|
-
case 0:
|
|
469
|
-
_context3.next = 2;
|
|
470
|
-
return this.db;
|
|
471
|
-
case 2:
|
|
472
|
-
db = _context3.sent;
|
|
473
|
-
_context3.next = 5;
|
|
474
|
-
return db.getAll(OBJECT_STORE_NAME);
|
|
475
|
-
case 5:
|
|
476
|
-
results = _context3.sent;
|
|
477
|
-
return _context3.abrupt("return", results);
|
|
478
|
-
case 7:
|
|
479
|
-
case "end":
|
|
480
|
-
return _context3.stop();
|
|
481
|
-
}
|
|
482
|
-
}, _callee3, this);
|
|
483
|
-
}));
|
|
484
|
-
function getAll() {
|
|
485
|
-
return _getAll.apply(this, arguments);
|
|
486
|
-
}
|
|
487
|
-
return getAll;
|
|
488
|
-
}();
|
|
489
|
-
return Persistor;
|
|
490
|
-
}();
|
|
491
|
-
|
|
492
|
-
var Status;
|
|
493
|
-
(function (Status) {
|
|
494
|
-
Status["PENDING"] = "PENDING";
|
|
495
|
-
Status["RUNNING"] = "RUNNING";
|
|
496
|
-
Status["FAILED"] = "FAILED";
|
|
497
|
-
Status["SUCCESS"] = "SUCCESS";
|
|
498
|
-
Status["CANCELED"] = "CANCELED";
|
|
499
|
-
Status["BLOCKED"] = "BLOCKED";
|
|
500
|
-
})(Status || (Status = {}));
|
|
501
|
-
var SYNC_POLLING_INTERVAL = 5000;
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
*
|
|
505
|
-
* Notes on statuses:
|
|
506
|
-
* - Success: last task has success status
|
|
507
|
-
* - Failed: any of task has been failed
|
|
508
|
-
* - Running: first task is not on pending
|
|
509
|
-
* - Pending: default state. not started
|
|
510
|
-
*
|
|
511
|
-
*/
|
|
512
|
-
var Queue = /*#__PURE__*/function () {
|
|
513
|
-
function Queue(options) {
|
|
514
|
-
this.state = {
|
|
515
|
-
status: Status.PENDING,
|
|
516
|
-
activeTaskIndex: 0,
|
|
517
|
-
tasks: {}
|
|
518
|
-
};
|
|
519
|
-
this.tasks = [];
|
|
520
|
-
this.storage = {};
|
|
521
|
-
this.id = options.id;
|
|
522
|
-
this.events = options.events;
|
|
523
|
-
this.actions = options.actions;
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Update queue status and trigger an event
|
|
527
|
-
*
|
|
528
|
-
*/
|
|
529
|
-
var _proto = Queue.prototype;
|
|
530
|
-
_proto.updateQueueStatus = function updateQueueStatus(status) {
|
|
531
|
-
this.state.status = status;
|
|
532
|
-
this.events.onUpdateListStatus(status);
|
|
533
|
-
};
|
|
534
|
-
_proto.updateActiveTaskIndex = function updateActiveTaskIndex(index) {
|
|
535
|
-
this.state.activeTaskIndex = index;
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
*
|
|
539
|
-
* Update task state (`status`, `blockedFor`) and trigger an event.
|
|
540
|
-
* @param id
|
|
541
|
-
* @param nextState
|
|
542
|
-
*/;
|
|
543
|
-
_proto.updateTaskState = function updateTaskState(id, nextState) {
|
|
544
|
-
if (nextState.status) {
|
|
545
|
-
this.state.tasks[id].status = nextState.status;
|
|
546
|
-
}
|
|
547
|
-
if (nextState.blockedFor) {
|
|
548
|
-
this.state.tasks[id].blockedFor = nextState.blockedFor;
|
|
549
|
-
}
|
|
550
|
-
var updatedTaskEvent = {
|
|
551
|
-
id: id,
|
|
552
|
-
task: this.get(id),
|
|
553
|
-
action: this.tasks.find(function (task) {
|
|
554
|
-
return task.id === id;
|
|
555
|
-
}).action
|
|
556
|
-
};
|
|
557
|
-
this.events.onUpdate(updatedTaskEvent);
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* Create a task by providing an `action` name.
|
|
561
|
-
*
|
|
562
|
-
* this method creating the task, push it to the queue's tasks and trigger an event.
|
|
563
|
-
* @param action
|
|
564
|
-
*/;
|
|
565
|
-
_proto.createTask = function createTask(action) {
|
|
566
|
-
var id = v4();
|
|
567
|
-
this.tasks.push({
|
|
568
|
-
action: action,
|
|
569
|
-
id: id
|
|
570
|
-
});
|
|
571
|
-
this.state.tasks[id] = {
|
|
572
|
-
status: Status.PENDING,
|
|
573
|
-
blockedFor: null
|
|
574
|
-
};
|
|
575
|
-
var createdTask = this.get(id);
|
|
576
|
-
this.events.onCreate({
|
|
577
|
-
id: id,
|
|
578
|
-
task: createdTask,
|
|
579
|
-
action: action
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
/**
|
|
583
|
-
* Initilize a queue with some tasks, instead of an empty queue.
|
|
584
|
-
*
|
|
585
|
-
* Using it for recover the queue state from persistor.
|
|
586
|
-
*
|
|
587
|
-
*/;
|
|
588
|
-
_proto.initTasks = function initTasks(info) {
|
|
589
|
-
var _this = this;
|
|
590
|
-
this.state = info.state;
|
|
591
|
-
this.storage = info.storage;
|
|
592
|
-
info.tasks.forEach(function (task) {
|
|
593
|
-
_this.tasks.push(task);
|
|
594
|
-
var action = _this.tasks.find(function (t) {
|
|
595
|
-
return t.id === task.id;
|
|
596
|
-
}).action;
|
|
597
|
-
_this.events.onCreate({
|
|
598
|
-
id: task.id,
|
|
599
|
-
task: _this.get(task.id),
|
|
600
|
-
action: action
|
|
601
|
-
});
|
|
602
|
-
});
|
|
603
|
-
};
|
|
604
|
-
_proto.checkBlock = function checkBlock() {
|
|
605
|
-
var currentActiveTask = this.getActiveTask();
|
|
606
|
-
if (!currentActiveTask) {
|
|
607
|
-
return;
|
|
608
|
-
}
|
|
609
|
-
var task = currentActiveTask.task,
|
|
610
|
-
state = currentActiveTask.state;
|
|
611
|
-
if (state.status === Status.BLOCKED) {
|
|
612
|
-
this.events.onBlock({
|
|
613
|
-
action: task.action,
|
|
614
|
-
id: task.id,
|
|
615
|
-
reason: state.blockedFor
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
/**
|
|
620
|
-
* Getting task state by ID
|
|
621
|
-
*/;
|
|
622
|
-
_proto.get = function get(id) {
|
|
623
|
-
var task = this.state.tasks[id];
|
|
624
|
-
if (!task) return null;
|
|
625
|
-
return task;
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
*
|
|
629
|
-
* Checking if status of the last is `SUCCESS` or not
|
|
630
|
-
*
|
|
631
|
-
*/;
|
|
632
|
-
_proto.lastTaskIsSuccessful = function lastTaskIsSuccessful() {
|
|
633
|
-
var lastTask = this.tasks[this.tasks.length - 1];
|
|
634
|
-
// checking for empty lists.
|
|
635
|
-
if (lastTask) {
|
|
636
|
-
var lastTaskState = this.state.tasks[lastTask.id];
|
|
637
|
-
// Maybe we didn't create the state yet. It should has success status as well.
|
|
638
|
-
if (!!lastTaskState && lastTaskState.status === Status.SUCCESS) {
|
|
639
|
-
return true;
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
return false;
|
|
643
|
-
}
|
|
644
|
-
/**
|
|
645
|
-
* If the first task started (it's not PENDING),
|
|
646
|
-
* it means the queue has been ran.
|
|
647
|
-
*
|
|
648
|
-
* @returns
|
|
649
|
-
*/;
|
|
650
|
-
_proto.firstTaskIsStarted = function firstTaskIsStarted() {
|
|
651
|
-
var firstTask = this.tasks[0];
|
|
652
|
-
// checking for empty lists.
|
|
653
|
-
if (firstTask) {
|
|
654
|
-
var firstTaskState = this.state.tasks[firstTask.id];
|
|
655
|
-
// Maybe we didn't create the state yet.
|
|
656
|
-
if (!!firstTaskState) {
|
|
657
|
-
if (firstTaskState.status !== Status.PENDING) {
|
|
658
|
-
return true;
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
return false;
|
|
663
|
-
}
|
|
664
|
-
/**
|
|
665
|
-
* Getting active task index from state and
|
|
666
|
-
* returns the task and its state.
|
|
667
|
-
*
|
|
668
|
-
*/;
|
|
669
|
-
_proto.getActiveTask = function getActiveTask() {
|
|
670
|
-
// First try to get task with `activeTask`
|
|
671
|
-
var index = this.state.activeTaskIndex;
|
|
672
|
-
var task = this.tasks[index];
|
|
673
|
-
// Consider all the tasks has been executed.
|
|
674
|
-
if (!task) {
|
|
675
|
-
return null;
|
|
676
|
-
}
|
|
677
|
-
var state = this.state.tasks[task.id];
|
|
678
|
-
return {
|
|
679
|
-
task: task,
|
|
680
|
-
state: state,
|
|
681
|
-
index: index
|
|
682
|
-
};
|
|
683
|
-
}
|
|
684
|
-
/**
|
|
685
|
-
* Update and find the queue status by checking state of each tasks in the queue.
|
|
686
|
-
*/;
|
|
687
|
-
_proto.check = function check() {
|
|
688
|
-
var currentListStatus = this.state.status;
|
|
689
|
-
var nextListStatus = this.firstTaskIsStarted() ? Status.RUNNING : Status.PENDING;
|
|
690
|
-
if (this.lastTaskIsSuccessful()) {
|
|
691
|
-
nextListStatus = Status.SUCCESS;
|
|
692
|
-
} else {
|
|
693
|
-
// Is there any failed task?
|
|
694
|
-
for (var _iterator = _createForOfIteratorHelperLoose(this.tasks), _step; !(_step = _iterator()).done;) {
|
|
695
|
-
var task = _step.value;
|
|
696
|
-
var state = this.state.tasks[task.id];
|
|
697
|
-
// If one item fails, we stop to work on the list.
|
|
698
|
-
if (state.status === Status.FAILED) {
|
|
699
|
-
nextListStatus = Status.FAILED;
|
|
700
|
-
break;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
// We only update and trigger an event when there is a new value
|
|
705
|
-
if (nextListStatus !== currentListStatus) {
|
|
706
|
-
this.updateQueueStatus(nextListStatus);
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* Execute active task.
|
|
711
|
-
* Based on the state of active task, the behaviour is different. If status is:
|
|
712
|
-
* - Success -> we need to go to next task by updating the active index and try `next` on more time.
|
|
713
|
-
* - Failed, Running, or no active task -> doesn't do anything.
|
|
714
|
-
* - Pending or Blocked -> update the task and queue status to running, and execute the provided `action` for the task.
|
|
715
|
-
*
|
|
716
|
-
* The queue is a linked list somehow, active task means the pointer to where we are in the queue right now.
|
|
717
|
-
*
|
|
718
|
-
*/;
|
|
719
|
-
_proto.next = function next(params) {
|
|
720
|
-
var _this2 = this;
|
|
721
|
-
this.check();
|
|
722
|
-
var currentActiveTask = this.getActiveTask();
|
|
723
|
-
if (!currentActiveTask) {
|
|
724
|
-
return;
|
|
725
|
-
}
|
|
726
|
-
var activeTaskIndex = currentActiveTask.index,
|
|
727
|
-
activeTask = currentActiveTask.task,
|
|
728
|
-
activeTaskState = currentActiveTask.state;
|
|
729
|
-
// if `activeTask` is already done, we will go for next one.
|
|
730
|
-
if (activeTaskState.status === Status.SUCCESS) {
|
|
731
|
-
this.updateActiveTaskIndex(activeTaskIndex + 1);
|
|
732
|
-
this.next(params);
|
|
733
|
-
return;
|
|
734
|
-
}
|
|
735
|
-
if ([Status.FAILED, Status.CANCELED, Status.RUNNING].includes(activeTaskState.status)) {
|
|
736
|
-
return;
|
|
737
|
-
}
|
|
738
|
-
if (activeTaskState.status === Status.PENDING || activeTaskState.status === Status.BLOCKED) {
|
|
739
|
-
// Update task status to `running`
|
|
740
|
-
this.updateTaskState(activeTask.id, {
|
|
741
|
-
status: Status.RUNNING
|
|
742
|
-
});
|
|
743
|
-
this.updateQueueStatus(Status.RUNNING);
|
|
744
|
-
// Try to execute task.
|
|
745
|
-
var execute = this.actions[activeTask.action];
|
|
746
|
-
execute({
|
|
747
|
-
context: this.getContext(params),
|
|
748
|
-
next: function next() {
|
|
749
|
-
_this2.markCurrentTaskAsFinished(params);
|
|
750
|
-
},
|
|
751
|
-
retry: function retry() {
|
|
752
|
-
_this2.resume(params);
|
|
753
|
-
},
|
|
754
|
-
failed: function failed() {
|
|
755
|
-
_this2.updateTaskState(activeTask.id, {
|
|
756
|
-
status: Status.FAILED
|
|
757
|
-
});
|
|
758
|
-
_this2.check();
|
|
759
|
-
},
|
|
760
|
-
schedule: function schedule(action) {
|
|
761
|
-
_this2.createTask(action);
|
|
762
|
-
_this2.check();
|
|
763
|
-
},
|
|
764
|
-
getStorage: this.getStorage.bind(this),
|
|
765
|
-
setStorage: this.setStorage.bind(this),
|
|
766
|
-
block: function block(reason) {
|
|
767
|
-
_this2.block({
|
|
768
|
-
reason: reason
|
|
769
|
-
});
|
|
770
|
-
},
|
|
771
|
-
unblock: function unblock() {
|
|
772
|
-
_this2.unblock();
|
|
773
|
-
}
|
|
774
|
-
});
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* Change the `status` of active task and queue to BLOCKED, then trigger an event.
|
|
779
|
-
*/;
|
|
780
|
-
_proto.block = function block(_ref) {
|
|
781
|
-
var reason = _ref.reason,
|
|
782
|
-
_ref$silent = _ref.silent,
|
|
783
|
-
silent = _ref$silent === void 0 ? false : _ref$silent;
|
|
784
|
-
var currentActiveTask = this.getActiveTask();
|
|
785
|
-
if (!currentActiveTask) {
|
|
786
|
-
throw new Error("Task isn't exist.");
|
|
787
|
-
}
|
|
788
|
-
this.updateTaskState(currentActiveTask.task.id, {
|
|
789
|
-
status: Status.BLOCKED,
|
|
790
|
-
blockedFor: reason
|
|
791
|
-
});
|
|
792
|
-
this.updateQueueStatus(Status.BLOCKED);
|
|
793
|
-
if (!silent) {
|
|
794
|
-
this.events.onBlock({
|
|
795
|
-
action: currentActiveTask.task.action,
|
|
796
|
-
id: currentActiveTask.task.id,
|
|
797
|
-
reason: reason
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
/**
|
|
802
|
-
* If the active task is `BLOCKED`, update the task status to `PENDING`, queue status to `RUNNING`
|
|
803
|
-
* then trigger an event.
|
|
804
|
-
*/;
|
|
805
|
-
_proto.unblock = function unblock() {
|
|
806
|
-
var currentActiveTask = this.getActiveTask();
|
|
807
|
-
if (!currentActiveTask || currentActiveTask.state.status !== Status.BLOCKED) {
|
|
808
|
-
throw new Error('Task is not blocked.');
|
|
809
|
-
}
|
|
810
|
-
this.updateTaskState(currentActiveTask.task.id, {
|
|
811
|
-
status: Status.PENDING
|
|
812
|
-
});
|
|
813
|
-
this.updateQueueStatus(Status.RUNNING);
|
|
814
|
-
this.events.onUnblock({
|
|
815
|
-
id: currentActiveTask.task.id
|
|
816
|
-
});
|
|
817
|
-
}
|
|
818
|
-
/**
|
|
819
|
-
* If the active task is `BLOCKED` then execute the `action` for the task.
|
|
820
|
-
*
|
|
821
|
-
* It is useful for when we need to run a blocked task without changing the status of task at the first place.
|
|
822
|
-
* For scenarios like we have some conditions in `action` and needs to run the `action` again
|
|
823
|
-
* to check the conditions are met or not, if yes, so we can proceed the `action`.
|
|
824
|
-
*
|
|
825
|
-
*/;
|
|
826
|
-
_proto.forceRun = function forceRun(params) {
|
|
827
|
-
var _this3 = this;
|
|
828
|
-
var currentTask = this.getActiveTask();
|
|
829
|
-
if (!currentTask || currentTask.state.status !== Status.BLOCKED) {
|
|
830
|
-
throw new Error('Task is not blocked.');
|
|
831
|
-
}
|
|
832
|
-
// Try to execute task.
|
|
833
|
-
var execute = this.actions[currentTask.task.action];
|
|
834
|
-
execute({
|
|
835
|
-
context: this.getContext(params),
|
|
836
|
-
next: function next() {
|
|
837
|
-
/*
|
|
838
|
-
NOTE:
|
|
839
|
-
When running `forceRun`, the status of task can be `BLOCKED`
|
|
840
|
-
So we need to change to `Running` first.
|
|
841
|
-
*/
|
|
842
|
-
// Update task status to `running`
|
|
843
|
-
_this3.updateTaskState(currentTask.task.id, {
|
|
844
|
-
status: Status.RUNNING
|
|
845
|
-
});
|
|
846
|
-
_this3.updateQueueStatus(Status.RUNNING);
|
|
847
|
-
_this3.markCurrentTaskAsFinished(params);
|
|
848
|
-
},
|
|
849
|
-
retry: function retry() {
|
|
850
|
-
_this3.resume(params);
|
|
851
|
-
},
|
|
852
|
-
failed: function failed() {
|
|
853
|
-
_this3.updateTaskState(currentTask.task.id, {
|
|
854
|
-
status: Status.FAILED
|
|
855
|
-
});
|
|
856
|
-
_this3.check();
|
|
857
|
-
},
|
|
858
|
-
schedule: function schedule(action) {
|
|
859
|
-
_this3.createTask(action);
|
|
860
|
-
_this3.check();
|
|
861
|
-
},
|
|
862
|
-
getStorage: this.getStorage.bind(this),
|
|
863
|
-
setStorage: this.setStorage.bind(this),
|
|
864
|
-
block: function block(reason) {
|
|
865
|
-
_this3.block({
|
|
866
|
-
reason: reason
|
|
867
|
-
});
|
|
868
|
-
},
|
|
869
|
-
unblock: function unblock() {
|
|
870
|
-
_this3.unblock();
|
|
871
|
-
}
|
|
872
|
-
});
|
|
873
|
-
};
|
|
874
|
-
_proto.markCurrentTaskAsFinished = function markCurrentTaskAsFinished(params) {
|
|
875
|
-
this.check();
|
|
876
|
-
var activeTaskIndex = this.state.activeTaskIndex;
|
|
877
|
-
var activeTask = this.tasks[activeTaskIndex];
|
|
878
|
-
if (!activeTask) return;
|
|
879
|
-
var activeTaskState = this.state.tasks[activeTask.id];
|
|
880
|
-
if (activeTaskState.status === Status.RUNNING) {
|
|
881
|
-
this.updateTaskState(activeTask.id, {
|
|
882
|
-
status: Status.SUCCESS
|
|
883
|
-
});
|
|
884
|
-
this.updateActiveTaskIndex(activeTaskIndex + 1);
|
|
885
|
-
var updatedTaskEvent = {
|
|
886
|
-
id: activeTask.id,
|
|
887
|
-
task: this.get(activeTask.id),
|
|
888
|
-
action: this.tasks.find(function (task) {
|
|
889
|
-
return task.id === activeTask.id;
|
|
890
|
-
}).action
|
|
891
|
-
};
|
|
892
|
-
this.events.onUpdate(updatedTaskEvent);
|
|
893
|
-
this.next(params);
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
/**
|
|
897
|
-
* If the active task is `RUNNING`, change it to `PENING` the try to run the task by calling `next`.
|
|
898
|
-
* If it's other than `RUNNING` we reset the queue state and run the queue from the beggining.
|
|
899
|
-
*
|
|
900
|
-
* @param params
|
|
901
|
-
* @returns
|
|
902
|
-
*/;
|
|
903
|
-
_proto.resume = function resume(params) {
|
|
904
|
-
var activeTaskIndex = this.state.activeTaskIndex;
|
|
905
|
-
var activeTask = this.tasks[activeTaskIndex];
|
|
906
|
-
if (!activeTask) return;
|
|
907
|
-
var activeTaskState = this.state.tasks[activeTask.id];
|
|
908
|
-
if (activeTaskState.status === Status.RUNNING) {
|
|
909
|
-
this.updateTaskState(activeTask.id, {
|
|
910
|
-
status: Status.PENDING
|
|
911
|
-
});
|
|
912
|
-
this.next(params);
|
|
913
|
-
} else {
|
|
914
|
-
this.resetState();
|
|
915
|
-
this.next(params);
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
/**
|
|
919
|
-
*
|
|
920
|
-
* Cancel the queue by changing active task and queue status to `CANCELED`.
|
|
921
|
-
*
|
|
922
|
-
*/;
|
|
923
|
-
_proto.cancel = function cancel() {
|
|
924
|
-
var currentActiveTask = this.getActiveTask();
|
|
925
|
-
if (!currentActiveTask || [Status.FAILED, Status.CANCELED, Status.SUCCESS].includes(currentActiveTask.state.status)) {
|
|
926
|
-
return;
|
|
927
|
-
}
|
|
928
|
-
var task = currentActiveTask.task;
|
|
929
|
-
// Update task status to `canceled`
|
|
930
|
-
this.updateTaskState(task.id, {
|
|
931
|
-
status: Status.CANCELED
|
|
932
|
-
});
|
|
933
|
-
var updatedTaskEvent = {
|
|
934
|
-
id: task.id,
|
|
935
|
-
task: this.get(task.id),
|
|
936
|
-
action: this.tasks.find(function (t) {
|
|
937
|
-
return t.id === task.id;
|
|
938
|
-
}).action
|
|
939
|
-
};
|
|
940
|
-
this.events.onUpdate(updatedTaskEvent);
|
|
941
|
-
// Update queue status to `canceled`
|
|
942
|
-
this.updateQueueStatus(Status.CANCELED);
|
|
943
|
-
}
|
|
944
|
-
/**
|
|
945
|
-
* Update queue status, and all the tasks inside queue to `PENDING`.
|
|
946
|
-
*/;
|
|
947
|
-
_proto.resetState = function resetState() {
|
|
948
|
-
var _this4 = this;
|
|
949
|
-
this.state.activeTaskIndex = 0;
|
|
950
|
-
this.state.status = Status.PENDING;
|
|
951
|
-
Object.keys(this.state.tasks).forEach(function (id) {
|
|
952
|
-
_this4.state.tasks[id].status = Status.PENDING;
|
|
953
|
-
});
|
|
954
|
-
};
|
|
955
|
-
_proto.getStorage = function getStorage() {
|
|
956
|
-
return this.storage;
|
|
957
|
-
};
|
|
958
|
-
_proto.setStorage = function setStorage(data) {
|
|
959
|
-
this.storage = data;
|
|
960
|
-
this.events.onStorageUpdate(data);
|
|
961
|
-
return this.storage;
|
|
962
|
-
};
|
|
963
|
-
_proto.getContext = function getContext(params) {
|
|
964
|
-
return _extends({}, params.context, {
|
|
965
|
-
_queue: {
|
|
966
|
-
id: this.id
|
|
967
|
-
}
|
|
968
|
-
});
|
|
969
|
-
};
|
|
970
|
-
return Queue;
|
|
971
|
-
}();
|
|
972
|
-
|
|
973
|
-
var Manager = /*#__PURE__*/function () {
|
|
974
|
-
/**
|
|
975
|
-
*
|
|
976
|
-
* Making an instance, initilize events, setup a persistor and try to recover the last state of the manager.
|
|
977
|
-
*
|
|
978
|
-
* */
|
|
979
|
-
function Manager(options) {
|
|
980
|
-
var _this = this;
|
|
981
|
-
this.queuesDefs = new Map();
|
|
982
|
-
this.queues = new Map();
|
|
983
|
-
this.isPaused = false;
|
|
984
|
-
// The client won't get any update on pause, We are using a polling mode to fix this issue for now.
|
|
985
|
-
this.syncInterval = null;
|
|
986
|
-
var defaultEventHandlers = {
|
|
987
|
-
onCreateQueue: function onCreateQueue() {
|
|
988
|
-
// ...
|
|
989
|
-
},
|
|
990
|
-
onCreateTask: function onCreateTask() {
|
|
991
|
-
// ...
|
|
992
|
-
},
|
|
993
|
-
onUpdateQueue: function onUpdateQueue() {
|
|
994
|
-
// ...
|
|
995
|
-
},
|
|
996
|
-
onUpdateTask: function onUpdateTask() {
|
|
997
|
-
// ...
|
|
998
|
-
},
|
|
999
|
-
onStorageUpdate: function onStorageUpdate() {
|
|
1000
|
-
// ...
|
|
1001
|
-
},
|
|
1002
|
-
onTaskBlock: function onTaskBlock() {
|
|
1003
|
-
// ...
|
|
1004
|
-
},
|
|
1005
|
-
onPersistedDataLoaded: function onPersistedDataLoaded() {
|
|
1006
|
-
// ..
|
|
1007
|
-
}
|
|
1008
|
-
};
|
|
1009
|
-
if (options.events) {
|
|
1010
|
-
this.events = _extends({}, defaultEventHandlers, options.events);
|
|
1011
|
-
} else {
|
|
1012
|
-
this.events = defaultEventHandlers;
|
|
1013
|
-
}
|
|
1014
|
-
options.queuesDefs.map(function (qDef) {
|
|
1015
|
-
_this.queuesDefs.set(qDef.name, qDef);
|
|
1016
|
-
});
|
|
1017
|
-
this.context = options.context || {};
|
|
1018
|
-
this.persistor = new Persistor();
|
|
1019
|
-
this.sync();
|
|
1020
|
-
if (options.isPaused) {
|
|
1021
|
-
this.pause();
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
/**
|
|
1025
|
-
*
|
|
1026
|
-
* Reading persisted data from storage then brings into memory.
|
|
1027
|
-
*
|
|
1028
|
-
* Notes:
|
|
1029
|
-
* - Reset the memory, so we can call this method whenever we want and not only on the initialize process.
|
|
1030
|
-
* - All the events will be tirggered (like onCreateQueue, onCreateTask, onBlock, ....)
|
|
1031
|
-
* - Try to `resume` if the status is `running`.
|
|
1032
|
-
* - Trigger `onPersistedDataLoaded` event when queues recovered from storage.
|
|
1033
|
-
*
|
|
1034
|
-
*/
|
|
1035
|
-
var _proto = Manager.prototype;
|
|
1036
|
-
_proto.sync =
|
|
1037
|
-
/*#__PURE__*/
|
|
1038
|
-
function () {
|
|
1039
|
-
var _sync = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1040
|
-
var _this2 = this;
|
|
1041
|
-
var queues;
|
|
1042
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1043
|
-
while (1) switch (_context.prev = _context.next) {
|
|
1044
|
-
case 0:
|
|
1045
|
-
_context.prev = 0;
|
|
1046
|
-
_context.next = 3;
|
|
1047
|
-
return this.persistor.getAll();
|
|
1048
|
-
case 3:
|
|
1049
|
-
queues = _context.sent;
|
|
1050
|
-
// Reset queues, if anything is exist in memory.
|
|
1051
|
-
this.queues = new Map();
|
|
1052
|
-
// Brings them into memory
|
|
1053
|
-
queues.forEach(function (q) {
|
|
1054
|
-
var list = _this2.createQueue({
|
|
1055
|
-
queue_id: q.id,
|
|
1056
|
-
queue_name: q.name
|
|
1057
|
-
});
|
|
1058
|
-
_this2.add(q.id, {
|
|
1059
|
-
list: list,
|
|
1060
|
-
createdAt: q.createdAt,
|
|
1061
|
-
name: q.name,
|
|
1062
|
-
status: q.status,
|
|
1063
|
-
actions: {
|
|
1064
|
-
run: function run() {
|
|
1065
|
-
list.next({
|
|
1066
|
-
context: _this2.getContext()
|
|
1067
|
-
});
|
|
1068
|
-
},
|
|
1069
|
-
cancel: function cancel() {
|
|
1070
|
-
list.cancel();
|
|
1071
|
-
},
|
|
1072
|
-
setStorage: function setStorage() {
|
|
1073
|
-
list.setStorage.apply(list, arguments);
|
|
1074
|
-
},
|
|
1075
|
-
getStorage: function getStorage() {
|
|
1076
|
-
return list.getStorage();
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
});
|
|
1080
|
-
list.initTasks({
|
|
1081
|
-
state: q.state,
|
|
1082
|
-
tasks: q.tasks,
|
|
1083
|
-
storage: q.storage || {}
|
|
1084
|
-
});
|
|
1085
|
-
if (q.status === Status.RUNNING && _this2.shouldExecute()) {
|
|
1086
|
-
list.resume({
|
|
1087
|
-
context: _this2.getContext()
|
|
1088
|
-
});
|
|
1089
|
-
}
|
|
1090
|
-
});
|
|
1091
|
-
_context.next = 11;
|
|
1092
|
-
break;
|
|
1093
|
-
case 8:
|
|
1094
|
-
_context.prev = 8;
|
|
1095
|
-
_context.t0 = _context["catch"](0);
|
|
1096
|
-
console.log("IndexDB Error: " + _context.t0);
|
|
1097
|
-
case 11:
|
|
1098
|
-
// Trigger an event to let the subscribers we are done here.
|
|
1099
|
-
this.events.onPersistedDataLoaded(this);
|
|
1100
|
-
case 12:
|
|
1101
|
-
case "end":
|
|
1102
|
-
return _context.stop();
|
|
1103
|
-
}
|
|
1104
|
-
}, _callee, this, [[0, 8]]);
|
|
1105
|
-
}));
|
|
1106
|
-
function sync() {
|
|
1107
|
-
return _sync.apply(this, arguments);
|
|
1108
|
-
}
|
|
1109
|
-
return sync;
|
|
1110
|
-
}()
|
|
1111
|
-
/**
|
|
1112
|
-
*
|
|
1113
|
-
* Making a new instance from `Queue` and adds Manager's event handlers to it.
|
|
1114
|
-
*
|
|
1115
|
-
* @returns An instance of `Queue` with wrapped event handlers from Manager.
|
|
1116
|
-
*
|
|
1117
|
-
*/
|
|
1118
|
-
;
|
|
1119
|
-
_proto.createQueue = function createQueue(_ref) {
|
|
1120
|
-
var _this3 = this;
|
|
1121
|
-
var queue_id = _ref.queue_id,
|
|
1122
|
-
queue_name = _ref.queue_name;
|
|
1123
|
-
var manager = this;
|
|
1124
|
-
var def = this.queuesDefs.get(queue_name);
|
|
1125
|
-
var list = new Queue({
|
|
1126
|
-
id: queue_id,
|
|
1127
|
-
events: {
|
|
1128
|
-
onCreate: function onCreate(task) {
|
|
1129
|
-
var _def$events;
|
|
1130
|
-
_this3.events.onCreateTask(queue_id, task);
|
|
1131
|
-
_this3.handleUpdate(queue_id);
|
|
1132
|
-
if ((_def$events = def.events) != null && _def$events.onCreate) def.events.onCreate(task);
|
|
1133
|
-
},
|
|
1134
|
-
onUpdate: function onUpdate(task) {
|
|
1135
|
-
var _def$events2;
|
|
1136
|
-
_this3.events.onUpdateTask(queue_id, task);
|
|
1137
|
-
_this3.handleUpdate(queue_id);
|
|
1138
|
-
if ((_def$events2 = def.events) != null && _def$events2.onUpdate) def.events.onUpdate(task);
|
|
1139
|
-
},
|
|
1140
|
-
onUpdateListStatus: function onUpdateListStatus(status) {
|
|
1141
|
-
var _def$events3;
|
|
1142
|
-
_this3.queues.set(queue_id, _extends({}, _this3.get(queue_id), {
|
|
1143
|
-
status: status
|
|
1144
|
-
}));
|
|
1145
|
-
_this3.events.onUpdateQueue(queue_id, _this3.get(queue_id));
|
|
1146
|
-
_this3.handleUpdate(queue_id);
|
|
1147
|
-
// After finishing a queue, try to run other queues.
|
|
1148
|
-
_this3.execute();
|
|
1149
|
-
if ((_def$events3 = def.events) != null && _def$events3.onUpdateListStatus) def.events.onUpdateListStatus(status);
|
|
1150
|
-
},
|
|
1151
|
-
onStorageUpdate: function onStorageUpdate(data) {
|
|
1152
|
-
var _def$events4;
|
|
1153
|
-
_this3.events.onStorageUpdate(queue_id, data);
|
|
1154
|
-
if ((_def$events4 = def.events) != null && _def$events4.onStorageUpdate) def.events.onStorageUpdate(data);
|
|
1155
|
-
_this3.handleUpdate(queue_id);
|
|
1156
|
-
},
|
|
1157
|
-
onBlock: function onBlock(event) {
|
|
1158
|
-
// Update queue status
|
|
1159
|
-
_this3.queues.set(queue_id, _extends({}, _this3.get(queue_id), {
|
|
1160
|
-
status: Status.BLOCKED
|
|
1161
|
-
}));
|
|
1162
|
-
// Trigger event
|
|
1163
|
-
_this3.events.onTaskBlock(queue_id);
|
|
1164
|
-
if (def.whenTaskBlocked) {
|
|
1165
|
-
def.whenTaskBlocked(event, {
|
|
1166
|
-
queue_id: queue_id,
|
|
1167
|
-
queue: list,
|
|
1168
|
-
context: _this3.getContext(),
|
|
1169
|
-
getBlockedTasks: _this3.getBlockedTasks.bind(_this3),
|
|
1170
|
-
forceExecute: _this3.forceExecute.bind(_this3),
|
|
1171
|
-
retry: _this3.retry.bind(_this3),
|
|
1172
|
-
manager: manager
|
|
1173
|
-
});
|
|
1174
|
-
}
|
|
1175
|
-
// Sync
|
|
1176
|
-
_this3.handleUpdate(queue_id);
|
|
1177
|
-
},
|
|
1178
|
-
onUnblock: function onUnblock() {
|
|
1179
|
-
// Update queue status
|
|
1180
|
-
_this3.queues.set(queue_id, _extends({}, _this3.get(queue_id), {
|
|
1181
|
-
status: Status.PENDING
|
|
1182
|
-
}));
|
|
1183
|
-
// Sync
|
|
1184
|
-
_this3.handleUpdate(queue_id);
|
|
1185
|
-
_this3.execute();
|
|
1186
|
-
}
|
|
1187
|
-
},
|
|
1188
|
-
actions: def.actions
|
|
1189
|
-
});
|
|
1190
|
-
return list;
|
|
1191
|
-
}
|
|
1192
|
-
/**
|
|
1193
|
-
* Go through all tasks (from all queues) and return a list of blocked tasks
|
|
1194
|
-
*
|
|
1195
|
-
* @returns a list of blocked tasks including enough information to get the queue and mutate the storage.
|
|
1196
|
-
*
|
|
1197
|
-
*/;
|
|
1198
|
-
_proto.getBlockedTasks = function getBlockedTasks() {
|
|
1199
|
-
var queues = this.getAll();
|
|
1200
|
-
var blockedTasks = [];
|
|
1201
|
-
queues.forEach(function (q, queue_id) {
|
|
1202
|
-
q.list.tasks.forEach(function (task) {
|
|
1203
|
-
var state = q.list.state.tasks[task.id];
|
|
1204
|
-
if (state.status === Status.BLOCKED) {
|
|
1205
|
-
blockedTasks.push({
|
|
1206
|
-
task_id: task.id,
|
|
1207
|
-
queue_id: queue_id,
|
|
1208
|
-
action: task.action,
|
|
1209
|
-
reason: state.blockedFor,
|
|
1210
|
-
storage: {
|
|
1211
|
-
get: function get() {
|
|
1212
|
-
return q.list.getStorage();
|
|
1213
|
-
},
|
|
1214
|
-
set: function set(data) {
|
|
1215
|
-
return q.list.setStorage(data);
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
|
-
});
|
|
1221
|
-
});
|
|
1222
|
-
return blockedTasks;
|
|
1223
|
-
}
|
|
1224
|
-
/**
|
|
1225
|
-
*
|
|
1226
|
-
* Add a queue to the manager to keep track of the queue and its state.
|
|
1227
|
-
*
|
|
1228
|
-
* @param id
|
|
1229
|
-
* @param queue
|
|
1230
|
-
* @returns
|
|
1231
|
-
*/;
|
|
1232
|
-
_proto.add = function add(id, queue) {
|
|
1233
|
-
this.queues.set(id, queue);
|
|
1234
|
-
var createdQueue = this.get(id);
|
|
1235
|
-
this.events.onCreateQueue(_extends({}, createdQueue, {
|
|
1236
|
-
id: id
|
|
1237
|
-
}));
|
|
1238
|
-
return createdQueue;
|
|
1239
|
-
}
|
|
1240
|
-
// Create a new queue
|
|
1241
|
-
/**
|
|
1242
|
-
*
|
|
1243
|
-
* Create a new queue by client.
|
|
1244
|
-
*
|
|
1245
|
-
* It will do the internal things to make a queue from definitions, and running using Manager.
|
|
1246
|
-
*
|
|
1247
|
-
* Notes:
|
|
1248
|
-
* - After creating the queue, it will be run automatically.
|
|
1249
|
-
*
|
|
1250
|
-
* @returns an ID for queue so it can be used to get the created queue later by client.
|
|
1251
|
-
*
|
|
1252
|
-
*/;
|
|
1253
|
-
_proto.create =
|
|
1254
|
-
/*#__PURE__*/
|
|
1255
|
-
function () {
|
|
1256
|
-
var _create = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(name, storage, options) {
|
|
1257
|
-
var _this4 = this;
|
|
1258
|
-
var def, queue_id, createdAt, list, createdQueue;
|
|
1259
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1260
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
1261
|
-
case 0:
|
|
1262
|
-
if (this.queuesDefs.has(name)) {
|
|
1263
|
-
_context2.next = 2;
|
|
1264
|
-
break;
|
|
1265
|
-
}
|
|
1266
|
-
throw new Error('You need to add a queue definition first.');
|
|
1267
|
-
case 2:
|
|
1268
|
-
_context2.prev = 2;
|
|
1269
|
-
def = this.queuesDefs.get(name);
|
|
1270
|
-
queue_id = (options == null ? void 0 : options.id) || v4();
|
|
1271
|
-
createdAt = Date.now();
|
|
1272
|
-
list = this.createQueue({
|
|
1273
|
-
queue_id: queue_id,
|
|
1274
|
-
queue_name: name
|
|
1275
|
-
});
|
|
1276
|
-
list.setStorage(storage);
|
|
1277
|
-
createdQueue = this.add(queue_id, {
|
|
1278
|
-
list: list,
|
|
1279
|
-
createdAt: createdAt,
|
|
1280
|
-
name: name,
|
|
1281
|
-
status: Status.PENDING,
|
|
1282
|
-
actions: {
|
|
1283
|
-
run: function run() {
|
|
1284
|
-
list.next({
|
|
1285
|
-
context: _this4.getContext()
|
|
1286
|
-
});
|
|
1287
|
-
},
|
|
1288
|
-
cancel: function cancel() {
|
|
1289
|
-
list.cancel();
|
|
1290
|
-
},
|
|
1291
|
-
setStorage: function setStorage() {
|
|
1292
|
-
list.setStorage.apply(list, arguments);
|
|
1293
|
-
},
|
|
1294
|
-
getStorage: function getStorage() {
|
|
1295
|
-
return list.getStorage();
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
}); // Persist initial queue
|
|
1299
|
-
// Note: we need to first insert the queue, and then it can be updated by internal events.
|
|
1300
|
-
_context2.next = 11;
|
|
1301
|
-
return this.persistor.insertQueue({
|
|
1302
|
-
id: queue_id,
|
|
1303
|
-
createdAt: createdAt,
|
|
1304
|
-
name: createdQueue.name,
|
|
1305
|
-
status: createdQueue.status,
|
|
1306
|
-
tasks: list.tasks,
|
|
1307
|
-
state: list.state,
|
|
1308
|
-
storage: list.getStorage()
|
|
1309
|
-
});
|
|
1310
|
-
case 11:
|
|
1311
|
-
// adding initial tasks
|
|
1312
|
-
def.run.forEach(function (action) {
|
|
1313
|
-
list.createTask(action);
|
|
1314
|
-
});
|
|
1315
|
-
// After creating a new queue, try to run.
|
|
1316
|
-
this.execute();
|
|
1317
|
-
return _context2.abrupt("return", queue_id);
|
|
1318
|
-
case 16:
|
|
1319
|
-
_context2.prev = 16;
|
|
1320
|
-
_context2.t0 = _context2["catch"](2);
|
|
1321
|
-
throw new Error(_context2.t0 == null ? void 0 : _context2.t0.message);
|
|
1322
|
-
case 19:
|
|
1323
|
-
case "end":
|
|
1324
|
-
return _context2.stop();
|
|
1325
|
-
}
|
|
1326
|
-
}, _callee2, this, [[2, 16]]);
|
|
1327
|
-
}));
|
|
1328
|
-
function create(_x, _x2, _x3) {
|
|
1329
|
-
return _create.apply(this, arguments);
|
|
1330
|
-
}
|
|
1331
|
-
return create;
|
|
1332
|
-
}()
|
|
1333
|
-
/**
|
|
1334
|
-
* Get a queue by its ID.
|
|
1335
|
-
*
|
|
1336
|
-
* @returns An object includes queue and its state in `Manager`.
|
|
1337
|
-
*/
|
|
1338
|
-
;
|
|
1339
|
-
_proto.get = function get(queue_id) {
|
|
1340
|
-
return this.queues.get(queue_id);
|
|
1341
|
-
}
|
|
1342
|
-
/**
|
|
1343
|
-
* Get all queues from `Manager`
|
|
1344
|
-
*
|
|
1345
|
-
* @returns a list of queues includes all the queues and their states.
|
|
1346
|
-
*/;
|
|
1347
|
-
_proto.getAll = function getAll() {
|
|
1348
|
-
return this.queues;
|
|
1349
|
-
}
|
|
1350
|
-
/**
|
|
1351
|
-
*
|
|
1352
|
-
* Ask from manager to run pending queues.
|
|
1353
|
-
*
|
|
1354
|
-
* It only try to run queues with `PENDING` status and ignore all the other statuses.
|
|
1355
|
-
*
|
|
1356
|
-
*/;
|
|
1357
|
-
_proto.execute = function execute() {
|
|
1358
|
-
if (!this.shouldExecute()) return;
|
|
1359
|
-
for (var _i = 0, _Array$from = Array.from(this.queues); _i < _Array$from.length; _i++) {
|
|
1360
|
-
var _Array$from$_i = _Array$from[_i],
|
|
1361
|
-
q = _Array$from$_i[1];
|
|
1362
|
-
if (q.status === Status.PENDING) {
|
|
1363
|
-
q.actions.run();
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
/**
|
|
1368
|
-
*
|
|
1369
|
-
* Try to find queues with `RUNNING` status to run them again.
|
|
1370
|
-
*
|
|
1371
|
-
* It's useful for recovering the queue at some certain points
|
|
1372
|
-
* like running a currepted task (reloaded when it was running) or needs manual trigger from UI.
|
|
1373
|
-
*
|
|
1374
|
-
* @returns
|
|
1375
|
-
*/;
|
|
1376
|
-
_proto.resume = function resume() {
|
|
1377
|
-
if (!this.shouldExecute()) return;
|
|
1378
|
-
for (var _i2 = 0, _Array$from2 = Array.from(this.queues); _i2 < _Array$from2.length; _i2++) {
|
|
1379
|
-
var _Array$from2$_i = _Array$from2[_i2],
|
|
1380
|
-
q = _Array$from2$_i[1];
|
|
1381
|
-
if (q.status === Status.RUNNING) {
|
|
1382
|
-
q.list.resume({
|
|
1383
|
-
context: this.getContext()
|
|
1384
|
-
});
|
|
1385
|
-
return;
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
// If there is no running queue, try to run a new queue.
|
|
1389
|
-
this.execute();
|
|
1390
|
-
}
|
|
1391
|
-
/**
|
|
1392
|
-
*
|
|
1393
|
-
* Run all `BLOCKED` queues once again.
|
|
1394
|
-
*
|
|
1395
|
-
* If a queue has `BLOCKED` status and the last task is `BLOCKED` as well,
|
|
1396
|
-
* The task will be run one more time.
|
|
1397
|
-
*
|
|
1398
|
-
* Useful for scenarios like we are blocking the queue under some conditions in task,
|
|
1399
|
-
* We can use this method to ask the queue to run the blocked task one more time and
|
|
1400
|
-
* maybe this time condtions are met and the queue can be proceed.
|
|
1401
|
-
*
|
|
1402
|
-
* @returns
|
|
1403
|
-
*/;
|
|
1404
|
-
_proto.retry = function retry() {
|
|
1405
|
-
if (!this.shouldExecute()) return;
|
|
1406
|
-
for (var _i3 = 0, _Array$from3 = Array.from(this.queues); _i3 < _Array$from3.length; _i3++) {
|
|
1407
|
-
var _Array$from3$_i = _Array$from3[_i3],
|
|
1408
|
-
q = _Array$from3$_i[1];
|
|
1409
|
-
if (q.status === Status.BLOCKED) {
|
|
1410
|
-
q.list.checkBlock();
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
// If there is no running queue, try to run a new queue.
|
|
1414
|
-
this.execute();
|
|
1415
|
-
}
|
|
1416
|
-
/**
|
|
1417
|
-
*
|
|
1418
|
-
* Run a blocked task on a specific queue with the ability to pass more data.
|
|
1419
|
-
*
|
|
1420
|
-
* Useful when we have a custom logic for running queue and needs to pass some specific data
|
|
1421
|
-
* to the task and try to run it manually with the provided data.
|
|
1422
|
-
*
|
|
1423
|
-
*/;
|
|
1424
|
-
_proto.forceExecute = function forceExecute(queue_id, data) {
|
|
1425
|
-
var queue = this.get(queue_id);
|
|
1426
|
-
var context = this.getContext();
|
|
1427
|
-
if (data) {
|
|
1428
|
-
context = _extends({}, context, data);
|
|
1429
|
-
}
|
|
1430
|
-
queue == null ? void 0 : queue.list.forceRun({
|
|
1431
|
-
context: context
|
|
1432
|
-
});
|
|
1433
|
-
}
|
|
1434
|
-
/**
|
|
1435
|
-
*
|
|
1436
|
-
* Sync in-memory state (of `Manager`) with storage (persist).
|
|
1437
|
-
*
|
|
1438
|
-
* Usually we call this method after a change detected in the state of manager.
|
|
1439
|
-
*
|
|
1440
|
-
*/;
|
|
1441
|
-
_proto.handleUpdate = function handleUpdate(queue_id) {
|
|
1442
|
-
var queue = this.get(queue_id);
|
|
1443
|
-
if (queue) {
|
|
1444
|
-
var status = queue.status;
|
|
1445
|
-
var state = queue.list.state;
|
|
1446
|
-
var tasks = queue.list.tasks;
|
|
1447
|
-
this.persistor.updateQueue(queue_id, {
|
|
1448
|
-
status: status,
|
|
1449
|
-
state: state,
|
|
1450
|
-
tasks: tasks,
|
|
1451
|
-
storage: queue.list.getStorage()
|
|
1452
|
-
});
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
/**
|
|
1456
|
-
* Active readonly mode for manager, it means it doesn't run anythin,
|
|
1457
|
-
* And only can be used to read the data.
|
|
1458
|
-
*/;
|
|
1459
|
-
_proto.pause = function pause() {
|
|
1460
|
-
var _this5 = this;
|
|
1461
|
-
if (this.isPaused) return;
|
|
1462
|
-
this.isPaused = true;
|
|
1463
|
-
this.syncInterval = setInterval(function () {
|
|
1464
|
-
_this5.sync();
|
|
1465
|
-
}, SYNC_POLLING_INTERVAL);
|
|
1466
|
-
}
|
|
1467
|
-
/**
|
|
1468
|
-
* Activate normal mode which means it will be able to run the queuese as well.
|
|
1469
|
-
*/;
|
|
1470
|
-
_proto.run = function run() {
|
|
1471
|
-
// If call this method multiple times, it should be run for once.
|
|
1472
|
-
if (this.isPaused) {
|
|
1473
|
-
this.isPaused = false;
|
|
1474
|
-
if (!!this.syncInterval) {
|
|
1475
|
-
clearInterval(this.syncInterval);
|
|
1476
|
-
this.syncInterval = null;
|
|
1477
|
-
}
|
|
1478
|
-
this.sync();
|
|
1479
|
-
}
|
|
1480
|
-
};
|
|
1481
|
-
_proto.getContext = function getContext() {
|
|
1482
|
-
var _this$context;
|
|
1483
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1484
|
-
//@ts-ignore
|
|
1485
|
-
return ((_this$context = this.context) == null ? void 0 : _this$context.current) || {};
|
|
1486
|
-
};
|
|
1487
|
-
_proto.shouldExecute = function shouldExecute() {
|
|
1488
|
-
return !this.isPaused;
|
|
1489
|
-
};
|
|
1490
|
-
return Manager;
|
|
1491
|
-
}();
|
|
1492
|
-
|
|
1493
|
-
export { DB_NAME, Manager, Persistor, SYNC_POLLING_INTERVAL, Status };
|
|
1494
|
-
//# sourceMappingURL=queue-manager-core.esm.js.map
|