@budibase/backend-core 2.12.4 → 2.12.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.js +63 -3
- package/dist/index.js.map +4 -4
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +4 -4
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/queue/inMemoryQueue.d.ts +1 -1
- package/dist/src/queue/inMemoryQueue.js +1 -1
- package/dist/src/queue/inMemoryQueue.js.map +1 -1
- package/dist/src/queue/queue.js +15 -2
- package/dist/src/queue/queue.js.map +1 -1
- package/dist/src/utils/Duration.d.ts +30 -0
- package/dist/src/utils/Duration.js +48 -0
- package/dist/src/utils/Duration.js.map +1 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/index.js +1 -0
- package/dist/src/utils/index.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/queue/inMemoryQueue.ts +1 -1
- package/src/queue/queue.ts +17 -3
- package/src/utils/Duration.ts +49 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/tests/Duration.spec.ts +19 -0
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/backend-core",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.6",
|
|
4
4
|
"description": "Budibase backend core libraries used in server and worker",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@budibase/nano": "10.1.3",
|
|
25
25
|
"@budibase/pouchdb-replication-stream": "1.2.10",
|
|
26
|
-
"@budibase/shared-core": "2.12.
|
|
27
|
-
"@budibase/types": "2.12.
|
|
26
|
+
"@budibase/shared-core": "2.12.6",
|
|
27
|
+
"@budibase/types": "2.12.6",
|
|
28
28
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
29
29
|
"aws-cloudfront-sign": "3.0.2",
|
|
30
30
|
"aws-sdk": "2.1030.0",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "1e5fcb443bf5906edc55237be7e70f4e20b66e42"
|
|
100
100
|
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export * as timers from "./timers";
|
|
|
30
30
|
export { default as env } from "./environment";
|
|
31
31
|
export * as blacklist from "./blacklist";
|
|
32
32
|
export * as docUpdates from "./docUpdates";
|
|
33
|
+
export * from "./utils/Duration";
|
|
33
34
|
export { SearchParams } from "./db";
|
|
34
35
|
import * as context from "./context";
|
|
35
36
|
export declare const tenancy: {
|
package/dist/src/index.js
CHANGED
|
@@ -64,6 +64,7 @@ var environment_1 = require("./environment");
|
|
|
64
64
|
Object.defineProperty(exports, "env", { enumerable: true, get: function () { return __importDefault(environment_1).default; } });
|
|
65
65
|
exports.blacklist = __importStar(require("./blacklist"));
|
|
66
66
|
exports.docUpdates = __importStar(require("./docUpdates"));
|
|
67
|
+
__exportStar(require("./utils/Duration"), exports);
|
|
67
68
|
// Add context to tenancy for backwards compatibility
|
|
68
69
|
// only do this for external usages to prevent internal
|
|
69
70
|
// circular dependencies
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAoC;AACpC,mDAAkC;AAClC,2DAA0C;AAC1C,iDAAgC;AAChC,0DAAyC;AACzC,sEAAqD;AACrD,uDAAsC;AACtC,+DAA8C;AAC9C,2DAA0C;AAC1C,oEAAmD;AACnD,gEAA+C;AAC/C,uDAAsC;AACtC,+CAA8B;AAC9B,yDAAwC;AACxC,qDAAoC;AACpC,2DAA0C;AAC1C,oDAAmC;AACnC,oEAAmD;AACnD,iDAAgC;AAChC,2CAA0B;AAC1B,qDAAoC;AACpC,iDAAgC;AAChC,6DAA4C;AAC5C,iDAAgC;AAChC,iCAA+C;AAAtC,oGAAA,MAAM,OAAe;AAC9B,6DAA4C;AAC5C,iDAAgC;AAChC,mDAAkC;AAClC,mDAAkC;AAClC,6CAA8C;AAArC,mHAAA,OAAO,OAAO;AACvB,yDAAwC;AACxC,2DAA0C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAoC;AACpC,mDAAkC;AAClC,2DAA0C;AAC1C,iDAAgC;AAChC,0DAAyC;AACzC,sEAAqD;AACrD,uDAAsC;AACtC,+DAA8C;AAC9C,2DAA0C;AAC1C,oEAAmD;AACnD,gEAA+C;AAC/C,uDAAsC;AACtC,+CAA8B;AAC9B,yDAAwC;AACxC,qDAAoC;AACpC,2DAA0C;AAC1C,oDAAmC;AACnC,oEAAmD;AACnD,iDAAgC;AAChC,2CAA0B;AAC1B,qDAAoC;AACpC,iDAAgC;AAChC,6DAA4C;AAC5C,iDAAgC;AAChC,iCAA+C;AAAtC,oGAAA,MAAM,OAAe;AAC9B,6DAA4C;AAC5C,iDAAgC;AAChC,mDAAkC;AAClC,mDAAkC;AAClC,6CAA8C;AAArC,mHAAA,OAAO,OAAO;AACvB,yDAAwC;AACxC,2DAA0C;AAC1C,mDAAgC;AAEhC,qDAAqD;AACrD,uDAAuD;AACvD,wBAAwB;AACxB,mDAAoC;AACpC,oDAAqC;AACxB,QAAA,OAAO,mCACf,QAAQ,GACR,OAAO,EACX;AAED,gCAAgC;AAChC,2CAAwB;AAExB,4BAA4B;AAC5B,8CAA2B;AAE3B,+BAA+B;AAC/B,yCAA0B;AACnB,MAAM,IAAI,GAAG,CAAC,OAAY,EAAE,EAAE,EAAE;IACrC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAClB,CAAC,CAAA;AAFY,QAAA,IAAI,QAEhB"}
|
|
@@ -17,7 +17,7 @@ declare class InMemoryQueue {
|
|
|
17
17
|
* @param opts This is not used by the in memory queue as there is no real use
|
|
18
18
|
* case when in memory, but is the same API as Bull
|
|
19
19
|
*/
|
|
20
|
-
constructor(name: string, opts?:
|
|
20
|
+
constructor(name: string, opts?: any);
|
|
21
21
|
/**
|
|
22
22
|
* Same callback API as Bull, each callback passed to this will consume messages as they are
|
|
23
23
|
* available. Please note this is a queue service, not a notification service, so each
|
|
@@ -42,7 +42,7 @@ class InMemoryQueue {
|
|
|
42
42
|
* @param opts This is not used by the in memory queue as there is no real use
|
|
43
43
|
* case when in memory, but is the same API as Bull
|
|
44
44
|
*/
|
|
45
|
-
constructor(name, opts
|
|
45
|
+
constructor(name, opts) {
|
|
46
46
|
this._name = name;
|
|
47
47
|
this._opts = opts;
|
|
48
48
|
this._messages = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inMemoryQueue.js","sourceRoot":"","sources":["../../../src/queue/inMemoryQueue.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,oDAA2B;AAC3B,oCAAkC;AAElC;;;;;;;;GAQG;AACH,SAAS,MAAM,CAAC,KAAa,EAAE,OAAY;IACzC,OAAO;QACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,OAAO;KACd,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,aAAa;IAOjB;;;;;OAKG;IACH,YAAY,IAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"inMemoryQueue.js","sourceRoot":"","sources":["../../../src/queue/inMemoryQueue.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,oDAA2B;AAC3B,oCAAkC;AAElC;;;;;;;;GAQG;AACH,SAAS,MAAM,CAAC,KAAa,EAAE,O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IAAI,CAAC,SAAS,EAAE,CAAA;QAChB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAC/B,CAAC;IAED;;OAEG;IACG,KAAK;;YACT,OAAO,EAAE,CAAA;QACX,CAAC;KAAA;IAED;;;OAGG;IACH,qBAAqB,CAAC,SAAiB;QACrC,8BAA8B;QAC9B,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;IACxB,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,OAAO,EAAE,CAAA;IACX,CAAC;IAED,0CAA0C;IAC1C,UAAU,CAAC,OAAe;QACxB,QAAQ;IACV,CAAC;IAED;;OAEG;IACG,KAAK;;YACT,OAAO,EAAE,CAAA;QACX,CAAC;KAAA;IAEK,MAAM;;YACV,OAAO,EAAE,CAAA;QACX,CAAC;KAAA;IAED,EAAE;QACA,aAAa;QACb,OAAO,IAAI,CAAA;IACb,CAAC;IAEK,iBAAiB;;YACrB,GAAG;gBACD,MAAM,IAAA,eAAO,EAAC,EAAE,CAAC,CAAA;aAClB,QAAQ,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,EAAC;QAC3C,CAAC;KAAA;CACF;AAED,kBAAe,aAAa,CAAA"}
|
package/dist/src/queue/queue.js
CHANGED
|
@@ -41,8 +41,14 @@ const utils_1 = require("../redis/utils");
|
|
|
41
41
|
const inMemoryQueue_1 = __importDefault(require("./inMemoryQueue"));
|
|
42
42
|
const bull_1 = __importDefault(require("bull"));
|
|
43
43
|
const listeners_1 = require("./listeners");
|
|
44
|
+
const utils_2 = require("../utils");
|
|
44
45
|
const timers = __importStar(require("../timers"));
|
|
45
|
-
|
|
46
|
+
// the queue lock is held for 5 minutes
|
|
47
|
+
const QUEUE_LOCK_MS = utils_2.Duration.fromMinutes(5).toMs();
|
|
48
|
+
// queue lock is refreshed every 30 seconds
|
|
49
|
+
const QUEUE_LOCK_RENEW_INTERNAL_MS = utils_2.Duration.fromSeconds(30).toMs();
|
|
50
|
+
// cleanup the queue every 60 seconds
|
|
51
|
+
const CLEANUP_PERIOD_MS = utils_2.Duration.fromSeconds(60).toMs();
|
|
46
52
|
let QUEUES = [];
|
|
47
53
|
let cleanupInterval;
|
|
48
54
|
function cleanup() {
|
|
@@ -54,7 +60,14 @@ function cleanup() {
|
|
|
54
60
|
}
|
|
55
61
|
function createQueue(jobQueue, opts = {}) {
|
|
56
62
|
const { opts: redisOpts, redisProtocolUrl } = (0, utils_1.getRedisOptions)();
|
|
57
|
-
const queueConfig =
|
|
63
|
+
const queueConfig = {
|
|
64
|
+
redis: redisProtocolUrl || redisOpts,
|
|
65
|
+
settings: {
|
|
66
|
+
maxStalledCount: 0,
|
|
67
|
+
lockDuration: QUEUE_LOCK_MS,
|
|
68
|
+
lockRenewTime: QUEUE_LOCK_RENEW_INTERNAL_MS,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
58
71
|
let queue;
|
|
59
72
|
if (!environment_1.default.isTest()) {
|
|
60
73
|
queue = new bull_1.default(jobQueue, queueConfig);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../src/queue/queue.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iEAAgC;AAChC,0CAAgD;AAEhD,oEAA2C;AAC3C,
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../src/queue/queue.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iEAAgC;AAChC,0CAAgD;AAEhD,oEAA2C;AAC3C,gDAA8C;AAC9C,2CAAqD;AACrD,oCAAmC;AACnC,kDAAmC;AAGnC,uCAAuC;AACvC,MAAM,aAAa,GAAG,gBAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;AACpD,2CAA2C;AAC3C,MAAM,4BAA4B,GAAG,gBAAQ,CAAC,WAAW,CAAC,E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AC,KAAK,CAAC,GAAG,CAAC,EAAE;YACpB,OAAO,CAAC,KAAK,CAAC,kDAAkD,GAAG,EAAE,CAAC,CAAA;QACxE,CAAC,CAAC,CAAA;KACH;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AA7BD,kCA6BC;AAED,SAAsB,QAAQ;;QAC5B,IAAI,eAAe,EAAE;YACnB,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;SAC9B;QACD,IAAI,MAAM,CAAC,MAAM,EAAE;YACjB,KAAK,IAAI,KAAK,IAAI,MAAM,EAAE;gBACxB,MAAM,KAAK,CAAC,KAAK,EAAE,CAAA;aACpB;YACD,MAAM,GAAG,EAAE,CAAA;SACZ;QACD,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAChC,CAAC;CAAA;AAXD,4BAWC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare enum DurationType {
|
|
2
|
+
MILLISECONDS = "milliseconds",
|
|
3
|
+
SECONDS = "seconds",
|
|
4
|
+
MINUTES = "minutes",
|
|
5
|
+
HOURS = "hours",
|
|
6
|
+
DAYS = "days"
|
|
7
|
+
}
|
|
8
|
+
export declare class Duration {
|
|
9
|
+
static convert(from: DurationType, to: DurationType, duration: number): number;
|
|
10
|
+
static from(from: DurationType, duration: number): {
|
|
11
|
+
to: (to: DurationType) => number;
|
|
12
|
+
toMs: () => number;
|
|
13
|
+
};
|
|
14
|
+
static fromSeconds(duration: number): {
|
|
15
|
+
to: (to: DurationType) => number;
|
|
16
|
+
toMs: () => number;
|
|
17
|
+
};
|
|
18
|
+
static fromMinutes(duration: number): {
|
|
19
|
+
to: (to: DurationType) => number;
|
|
20
|
+
toMs: () => number;
|
|
21
|
+
};
|
|
22
|
+
static fromHours(duration: number): {
|
|
23
|
+
to: (to: DurationType) => number;
|
|
24
|
+
toMs: () => number;
|
|
25
|
+
};
|
|
26
|
+
static fromDays(duration: number): {
|
|
27
|
+
to: (to: DurationType) => number;
|
|
28
|
+
toMs: () => number;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Duration = exports.DurationType = void 0;
|
|
4
|
+
var DurationType;
|
|
5
|
+
(function (DurationType) {
|
|
6
|
+
DurationType["MILLISECONDS"] = "milliseconds";
|
|
7
|
+
DurationType["SECONDS"] = "seconds";
|
|
8
|
+
DurationType["MINUTES"] = "minutes";
|
|
9
|
+
DurationType["HOURS"] = "hours";
|
|
10
|
+
DurationType["DAYS"] = "days";
|
|
11
|
+
})(DurationType || (exports.DurationType = DurationType = {}));
|
|
12
|
+
const conversion = {
|
|
13
|
+
milliseconds: 1,
|
|
14
|
+
seconds: 1000,
|
|
15
|
+
minutes: 60 * 1000,
|
|
16
|
+
hours: 60 * 60 * 1000,
|
|
17
|
+
days: 24 * 60 * 60 * 1000,
|
|
18
|
+
};
|
|
19
|
+
class Duration {
|
|
20
|
+
static convert(from, to, duration) {
|
|
21
|
+
const milliseconds = duration * conversion[from];
|
|
22
|
+
return milliseconds / conversion[to];
|
|
23
|
+
}
|
|
24
|
+
static from(from, duration) {
|
|
25
|
+
return {
|
|
26
|
+
to: (to) => {
|
|
27
|
+
return Duration.convert(from, to, duration);
|
|
28
|
+
},
|
|
29
|
+
toMs: () => {
|
|
30
|
+
return Duration.convert(from, DurationType.MILLISECONDS, duration);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
static fromSeconds(duration) {
|
|
35
|
+
return Duration.from(DurationType.SECONDS, duration);
|
|
36
|
+
}
|
|
37
|
+
static fromMinutes(duration) {
|
|
38
|
+
return Duration.from(DurationType.MINUTES, duration);
|
|
39
|
+
}
|
|
40
|
+
static fromHours(duration) {
|
|
41
|
+
return Duration.from(DurationType.HOURS, duration);
|
|
42
|
+
}
|
|
43
|
+
static fromDays(duration) {
|
|
44
|
+
return Duration.from(DurationType.DAYS, duration);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.Duration = Duration;
|
|
48
|
+
//# sourceMappingURL=Duration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Duration.js","sourceRoot":"","sources":["../../../src/utils/Duration.ts"],"names":[],"mappings":";;;AAAA,IAAY,YAMX;AAND,WAAY,YAAY;IACtB,6CAA6B,CAAA;IAC7B,mCAAmB,CAAA;IACnB,mCAAmB,CAAA;IACnB,+BAAe,CAAA;IACf,6BAAa,CAAA;AACf,CAAC,EANW,YAAY,4BAAZ,YAAY,QAMvB;AAED,MAAM,UAAU,GAAiC;IAC/C,YAAY,EAAE,CAAC;IACf,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,EAAE,GAAG,IAAI;IAClB,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACrB,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;CAC1B,CAAA;AAED,MAAa,QAAQ;IACnB,MAAM,CAAC,OAAO,CAAC,IAAkB,EAAE,EAAgB,EAAE,QAAgB;QACnE,MAAM,YAAY,GAAG,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;QAChD,OAAO,YAAY,GAAG,UAAU,CAAC,EAAE,CAAC,CAAA;IACtC,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,IAAkB,EAAE,QAAgB;QAC9C,OAAO;YACL,EAAE,EAAE,CAAC,EAAgB,EAAE,EAAE;gBACvB,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;YAC7C,CAAC;YACD,IAAI,EAAE,GAAG,EAAE;gBACT,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAA;YACpE,CAAC;SACF,CAAA;IACH,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,QAAgB;QACjC,OAAO,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IACtD,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,QAAgB;QACjC,OAAO,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IACtD,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,QAAgB;QAC/B,OAAO,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IACpD,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,QAAgB;QAC9B,OAAO,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IACnD,CAAC;CACF;AAhCD,4BAgCC"}
|
package/dist/src/utils/index.js
CHANGED
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./hashing"), exports);
|
|
18
18
|
__exportStar(require("./utils"), exports);
|
|
19
19
|
__exportStar(require("./stringUtils"), exports);
|
|
20
|
+
__exportStar(require("./Duration"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,0CAAuB;AACvB,gDAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,0CAAuB;AACvB,gDAA6B;AAC7B,6CAA0B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/backend-core",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.6",
|
|
4
4
|
"description": "Budibase backend core libraries used in server and worker",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@budibase/nano": "10.1.3",
|
|
25
25
|
"@budibase/pouchdb-replication-stream": "1.2.10",
|
|
26
|
-
"@budibase/shared-core": "2.12.
|
|
27
|
-
"@budibase/types": "2.12.
|
|
26
|
+
"@budibase/shared-core": "2.12.6",
|
|
27
|
+
"@budibase/types": "2.12.6",
|
|
28
28
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
29
29
|
"aws-cloudfront-sign": "3.0.2",
|
|
30
30
|
"aws-sdk": "2.1030.0",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "1e5fcb443bf5906edc55237be7e70f4e20b66e42"
|
|
100
100
|
}
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ export * as timers from "./timers"
|
|
|
30
30
|
export { default as env } from "./environment"
|
|
31
31
|
export * as blacklist from "./blacklist"
|
|
32
32
|
export * as docUpdates from "./docUpdates"
|
|
33
|
+
export * from "./utils/Duration"
|
|
33
34
|
export { SearchParams } from "./db"
|
|
34
35
|
// Add context to tenancy for backwards compatibility
|
|
35
36
|
// only do this for external usages to prevent internal
|
|
@@ -36,7 +36,7 @@ class InMemoryQueue {
|
|
|
36
36
|
* @param opts This is not used by the in memory queue as there is no real use
|
|
37
37
|
* case when in memory, but is the same API as Bull
|
|
38
38
|
*/
|
|
39
|
-
constructor(name: string, opts
|
|
39
|
+
constructor(name: string, opts?: any) {
|
|
40
40
|
this._name = name
|
|
41
41
|
this._opts = opts
|
|
42
42
|
this._messages = []
|
package/src/queue/queue.ts
CHANGED
|
@@ -2,11 +2,18 @@ import env from "../environment"
|
|
|
2
2
|
import { getRedisOptions } from "../redis/utils"
|
|
3
3
|
import { JobQueue } from "./constants"
|
|
4
4
|
import InMemoryQueue from "./inMemoryQueue"
|
|
5
|
-
import BullQueue from "bull"
|
|
5
|
+
import BullQueue, { QueueOptions } from "bull"
|
|
6
6
|
import { addListeners, StalledFn } from "./listeners"
|
|
7
|
+
import { Duration } from "../utils"
|
|
7
8
|
import * as timers from "../timers"
|
|
9
|
+
import * as Redis from "ioredis"
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
// the queue lock is held for 5 minutes
|
|
12
|
+
const QUEUE_LOCK_MS = Duration.fromMinutes(5).toMs()
|
|
13
|
+
// queue lock is refreshed every 30 seconds
|
|
14
|
+
const QUEUE_LOCK_RENEW_INTERNAL_MS = Duration.fromSeconds(30).toMs()
|
|
15
|
+
// cleanup the queue every 60 seconds
|
|
16
|
+
const CLEANUP_PERIOD_MS = Duration.fromSeconds(60).toMs()
|
|
10
17
|
let QUEUES: BullQueue.Queue[] | InMemoryQueue[] = []
|
|
11
18
|
let cleanupInterval: NodeJS.Timeout
|
|
12
19
|
|
|
@@ -21,7 +28,14 @@ export function createQueue<T>(
|
|
|
21
28
|
opts: { removeStalledCb?: StalledFn } = {}
|
|
22
29
|
): BullQueue.Queue<T> {
|
|
23
30
|
const { opts: redisOpts, redisProtocolUrl } = getRedisOptions()
|
|
24
|
-
const queueConfig:
|
|
31
|
+
const queueConfig: QueueOptions = {
|
|
32
|
+
redis: redisProtocolUrl! || (redisOpts as Redis.RedisOptions),
|
|
33
|
+
settings: {
|
|
34
|
+
maxStalledCount: 0,
|
|
35
|
+
lockDuration: QUEUE_LOCK_MS,
|
|
36
|
+
lockRenewTime: QUEUE_LOCK_RENEW_INTERNAL_MS,
|
|
37
|
+
},
|
|
38
|
+
}
|
|
25
39
|
let queue: any
|
|
26
40
|
if (!env.isTest()) {
|
|
27
41
|
queue = new BullQueue(jobQueue, queueConfig)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export enum DurationType {
|
|
2
|
+
MILLISECONDS = "milliseconds",
|
|
3
|
+
SECONDS = "seconds",
|
|
4
|
+
MINUTES = "minutes",
|
|
5
|
+
HOURS = "hours",
|
|
6
|
+
DAYS = "days",
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const conversion: Record<DurationType, number> = {
|
|
10
|
+
milliseconds: 1,
|
|
11
|
+
seconds: 1000,
|
|
12
|
+
minutes: 60 * 1000,
|
|
13
|
+
hours: 60 * 60 * 1000,
|
|
14
|
+
days: 24 * 60 * 60 * 1000,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class Duration {
|
|
18
|
+
static convert(from: DurationType, to: DurationType, duration: number) {
|
|
19
|
+
const milliseconds = duration * conversion[from]
|
|
20
|
+
return milliseconds / conversion[to]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static from(from: DurationType, duration: number) {
|
|
24
|
+
return {
|
|
25
|
+
to: (to: DurationType) => {
|
|
26
|
+
return Duration.convert(from, to, duration)
|
|
27
|
+
},
|
|
28
|
+
toMs: () => {
|
|
29
|
+
return Duration.convert(from, DurationType.MILLISECONDS, duration)
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static fromSeconds(duration: number) {
|
|
35
|
+
return Duration.from(DurationType.SECONDS, duration)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static fromMinutes(duration: number) {
|
|
39
|
+
return Duration.from(DurationType.MINUTES, duration)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static fromHours(duration: number) {
|
|
43
|
+
return Duration.from(DurationType.HOURS, duration)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static fromDays(duration: number) {
|
|
47
|
+
return Duration.from(DurationType.DAYS, duration)
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Duration, DurationType } from "../Duration"
|
|
2
|
+
|
|
3
|
+
describe("duration", () => {
|
|
4
|
+
it("should convert minutes to milliseconds", () => {
|
|
5
|
+
expect(Duration.fromMinutes(5).toMs()).toBe(300000)
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
it("should convert seconds to milliseconds", () => {
|
|
9
|
+
expect(Duration.fromSeconds(30).toMs()).toBe(30000)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it("should convert days to milliseconds", () => {
|
|
13
|
+
expect(Duration.fromDays(1).toMs()).toBe(86400000)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it("should convert minutes to days", () => {
|
|
17
|
+
expect(Duration.fromMinutes(1440).to(DurationType.DAYS)).toBe(1)
|
|
18
|
+
})
|
|
19
|
+
})
|