@trigger.dev/redis-worker 0.0.0-prerelease-20250430152137 → 0.0.0-process-keep-alive-20250618143615
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.cjs +555 -173
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -8
- package/dist/index.d.ts +34 -8
- package/dist/index.js +549 -173
- package/dist/index.js.map +1 -1
- package/package.json +4 -6
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var process2 = require('process');
|
|
4
|
+
var os = require('os');
|
|
5
|
+
var tty = require('tty');
|
|
3
6
|
var logger$1 = require('@trigger.dev/core/logger');
|
|
4
7
|
var crypto = require('crypto');
|
|
5
8
|
require('@trigger.dev/core/v3/utils/flattenAttributes');
|
|
6
9
|
var v3 = require('@trigger.dev/core/v3');
|
|
7
10
|
var serverOnly = require('@trigger.dev/core/v3/serverOnly');
|
|
8
|
-
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var process2__default = /*#__PURE__*/_interopDefault(process2);
|
|
15
|
+
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
16
|
+
var tty__default = /*#__PURE__*/_interopDefault(tty);
|
|
9
17
|
|
|
10
18
|
var __create = Object.create;
|
|
11
19
|
var __defProp = Object.defineProperty;
|
|
@@ -19,9 +27,16 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
19
27
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
20
28
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
21
29
|
});
|
|
30
|
+
var __esm = (fn, res) => function __init() {
|
|
31
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
32
|
+
};
|
|
22
33
|
var __commonJS = (cb, mod) => function __require2() {
|
|
23
34
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
24
35
|
};
|
|
36
|
+
var __export = (target, all) => {
|
|
37
|
+
for (var name in all)
|
|
38
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
39
|
+
};
|
|
25
40
|
var __copyProps = (to, from, except, desc) => {
|
|
26
41
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
42
|
for (let key of __getOwnPropNames(from))
|
|
@@ -38,6 +53,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
38
53
|
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
39
54
|
mod
|
|
40
55
|
));
|
|
56
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
57
|
|
|
42
58
|
// ../../node_modules/.pnpm/@ioredis+commands@1.2.0/node_modules/@ioredis/commands/built/commands.json
|
|
43
59
|
var require_commands = __commonJS({
|
|
@@ -2513,13 +2529,13 @@ var require_built = __commonJS({
|
|
|
2513
2529
|
return Boolean(commands_json_1.default[commandName]);
|
|
2514
2530
|
}
|
|
2515
2531
|
exports.exists = exists;
|
|
2516
|
-
function
|
|
2532
|
+
function hasFlag2(commandName, flag) {
|
|
2517
2533
|
if (!flags[commandName]) {
|
|
2518
2534
|
throw new Error("Unknown command " + commandName);
|
|
2519
2535
|
}
|
|
2520
2536
|
return Boolean(flags[commandName][flag]);
|
|
2521
2537
|
}
|
|
2522
|
-
exports.hasFlag =
|
|
2538
|
+
exports.hasFlag = hasFlag2;
|
|
2523
2539
|
function getKeyIndexes(commandName, args, options) {
|
|
2524
2540
|
const command = commands_json_1.default[commandName];
|
|
2525
2541
|
if (!command) {
|
|
@@ -3567,10 +3583,10 @@ var require_ms = __commonJS({
|
|
|
3567
3583
|
}
|
|
3568
3584
|
});
|
|
3569
3585
|
|
|
3570
|
-
// ../../node_modules/.pnpm/debug@4.3.
|
|
3586
|
+
// ../../node_modules/.pnpm/debug@4.3.7_supports-color@10.0.0/node_modules/debug/src/common.js
|
|
3571
3587
|
var require_common = __commonJS({
|
|
3572
|
-
"../../node_modules/.pnpm/debug@4.3.
|
|
3573
|
-
function setup(
|
|
3588
|
+
"../../node_modules/.pnpm/debug@4.3.7_supports-color@10.0.0/node_modules/debug/src/common.js"(exports, module) {
|
|
3589
|
+
function setup(env2) {
|
|
3574
3590
|
createDebug.debug = createDebug;
|
|
3575
3591
|
createDebug.default = createDebug;
|
|
3576
3592
|
createDebug.coerce = coerce;
|
|
@@ -3579,8 +3595,8 @@ var require_common = __commonJS({
|
|
|
3579
3595
|
createDebug.enabled = enabled;
|
|
3580
3596
|
createDebug.humanize = require_ms();
|
|
3581
3597
|
createDebug.destroy = destroy;
|
|
3582
|
-
Object.keys(
|
|
3583
|
-
createDebug[key] =
|
|
3598
|
+
Object.keys(env2).forEach((key) => {
|
|
3599
|
+
createDebug[key] = env2[key];
|
|
3584
3600
|
});
|
|
3585
3601
|
createDebug.names = [];
|
|
3586
3602
|
createDebug.skips = [];
|
|
@@ -3730,9 +3746,9 @@ var require_common = __commonJS({
|
|
|
3730
3746
|
}
|
|
3731
3747
|
});
|
|
3732
3748
|
|
|
3733
|
-
// ../../node_modules/.pnpm/debug@4.3.
|
|
3749
|
+
// ../../node_modules/.pnpm/debug@4.3.7_supports-color@10.0.0/node_modules/debug/src/browser.js
|
|
3734
3750
|
var require_browser = __commonJS({
|
|
3735
|
-
"../../node_modules/.pnpm/debug@4.3.
|
|
3751
|
+
"../../node_modules/.pnpm/debug@4.3.7_supports-color@10.0.0/node_modules/debug/src/browser.js"(exports, module) {
|
|
3736
3752
|
exports.formatArgs = formatArgs;
|
|
3737
3753
|
exports.save = save;
|
|
3738
3754
|
exports.load = load;
|
|
@@ -3900,117 +3916,150 @@ var require_browser = __commonJS({
|
|
|
3900
3916
|
}
|
|
3901
3917
|
});
|
|
3902
3918
|
|
|
3903
|
-
// ../../node_modules/.pnpm/
|
|
3904
|
-
var
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
3909
|
-
const pos = argv.indexOf(prefix + flag);
|
|
3910
|
-
const terminatorPos = argv.indexOf("--");
|
|
3911
|
-
return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
|
|
3912
|
-
};
|
|
3913
|
-
}
|
|
3919
|
+
// ../../node_modules/.pnpm/supports-color@10.0.0/node_modules/supports-color/index.js
|
|
3920
|
+
var supports_color_exports = {};
|
|
3921
|
+
__export(supports_color_exports, {
|
|
3922
|
+
createSupportsColor: () => createSupportsColor,
|
|
3923
|
+
default: () => supports_color_default
|
|
3914
3924
|
});
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3925
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2__default.default.argv) {
|
|
3926
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
3927
|
+
const position = argv.indexOf(prefix + flag);
|
|
3928
|
+
const terminatorPosition = argv.indexOf("--");
|
|
3929
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
3930
|
+
}
|
|
3931
|
+
function envForceColor() {
|
|
3932
|
+
if (!("FORCE_COLOR" in env)) {
|
|
3933
|
+
return;
|
|
3934
|
+
}
|
|
3935
|
+
if (env.FORCE_COLOR === "true") {
|
|
3936
|
+
return 1;
|
|
3937
|
+
}
|
|
3938
|
+
if (env.FORCE_COLOR === "false") {
|
|
3939
|
+
return 0;
|
|
3940
|
+
}
|
|
3941
|
+
if (env.FORCE_COLOR.length === 0) {
|
|
3942
|
+
return 1;
|
|
3943
|
+
}
|
|
3944
|
+
const level = Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
3945
|
+
if (![0, 1, 2, 3].includes(level)) {
|
|
3946
|
+
return;
|
|
3947
|
+
}
|
|
3948
|
+
return level;
|
|
3949
|
+
}
|
|
3950
|
+
function translateLevel(level) {
|
|
3951
|
+
if (level === 0) {
|
|
3952
|
+
return false;
|
|
3953
|
+
}
|
|
3954
|
+
return {
|
|
3955
|
+
level,
|
|
3956
|
+
hasBasic: true,
|
|
3957
|
+
has256: level >= 2,
|
|
3958
|
+
has16m: level >= 3
|
|
3959
|
+
};
|
|
3960
|
+
}
|
|
3961
|
+
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
3962
|
+
const noFlagForceColor = envForceColor();
|
|
3963
|
+
if (noFlagForceColor !== void 0) {
|
|
3964
|
+
flagForceColor = noFlagForceColor;
|
|
3965
|
+
}
|
|
3966
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
3967
|
+
if (forceColor === 0) {
|
|
3968
|
+
return 0;
|
|
3969
|
+
}
|
|
3970
|
+
if (sniffFlags) {
|
|
3971
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
3972
|
+
return 3;
|
|
3927
3973
|
}
|
|
3928
|
-
if ("
|
|
3929
|
-
|
|
3974
|
+
if (hasFlag("color=256")) {
|
|
3975
|
+
return 2;
|
|
3930
3976
|
}
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3977
|
+
}
|
|
3978
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
3979
|
+
return 1;
|
|
3980
|
+
}
|
|
3981
|
+
if (haveStream && !streamIsTTY && forceColor === void 0) {
|
|
3982
|
+
return 0;
|
|
3983
|
+
}
|
|
3984
|
+
const min = forceColor || 0;
|
|
3985
|
+
if (env.TERM === "dumb") {
|
|
3986
|
+
return min;
|
|
3987
|
+
}
|
|
3988
|
+
if (process2__default.default.platform === "win32") {
|
|
3989
|
+
const osRelease = os__default.default.release().split(".");
|
|
3990
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
3991
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
3941
3992
|
}
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
return min;
|
|
3968
|
-
}
|
|
3969
|
-
if ("TEAMCITY_VERSION" in env) {
|
|
3970
|
-
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
3971
|
-
}
|
|
3972
|
-
if (env.COLORTERM === "truecolor") {
|
|
3973
|
-
return 3;
|
|
3974
|
-
}
|
|
3975
|
-
if ("TERM_PROGRAM" in env) {
|
|
3976
|
-
const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
3977
|
-
switch (env.TERM_PROGRAM) {
|
|
3978
|
-
case "iTerm.app":
|
|
3979
|
-
return version >= 3 ? 3 : 2;
|
|
3980
|
-
case "Apple_Terminal":
|
|
3981
|
-
return 2;
|
|
3982
|
-
}
|
|
3993
|
+
return 1;
|
|
3994
|
+
}
|
|
3995
|
+
if ("CI" in env) {
|
|
3996
|
+
if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
|
|
3997
|
+
return 3;
|
|
3998
|
+
}
|
|
3999
|
+
if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
4000
|
+
return 1;
|
|
4001
|
+
}
|
|
4002
|
+
return min;
|
|
4003
|
+
}
|
|
4004
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
4005
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
4006
|
+
}
|
|
4007
|
+
if (env.COLORTERM === "truecolor") {
|
|
4008
|
+
return 3;
|
|
4009
|
+
}
|
|
4010
|
+
if (env.TERM === "xterm-kitty") {
|
|
4011
|
+
return 3;
|
|
4012
|
+
}
|
|
4013
|
+
if ("TERM_PROGRAM" in env) {
|
|
4014
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
4015
|
+
switch (env.TERM_PROGRAM) {
|
|
4016
|
+
case "iTerm.app": {
|
|
4017
|
+
return version >= 3 ? 3 : 2;
|
|
3983
4018
|
}
|
|
3984
|
-
|
|
4019
|
+
case "Apple_Terminal": {
|
|
3985
4020
|
return 2;
|
|
3986
4021
|
}
|
|
3987
|
-
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
3988
|
-
return 1;
|
|
3989
|
-
}
|
|
3990
|
-
if ("COLORTERM" in env) {
|
|
3991
|
-
return 1;
|
|
3992
|
-
}
|
|
3993
|
-
if (env.TERM === "dumb") {
|
|
3994
|
-
return min;
|
|
3995
|
-
}
|
|
3996
|
-
return min;
|
|
3997
4022
|
}
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4023
|
+
}
|
|
4024
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
4025
|
+
return 2;
|
|
4026
|
+
}
|
|
4027
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
4028
|
+
return 1;
|
|
4029
|
+
}
|
|
4030
|
+
if ("COLORTERM" in env) {
|
|
4031
|
+
return 1;
|
|
4032
|
+
}
|
|
4033
|
+
return min;
|
|
4034
|
+
}
|
|
4035
|
+
function createSupportsColor(stream, options = {}) {
|
|
4036
|
+
const level = _supportsColor(stream, {
|
|
4037
|
+
streamIsTTY: stream && stream.isTTY,
|
|
4038
|
+
...options
|
|
4039
|
+
});
|
|
4040
|
+
return translateLevel(level);
|
|
4041
|
+
}
|
|
4042
|
+
var env, flagForceColor, supportsColor, supports_color_default;
|
|
4043
|
+
var init_supports_color = __esm({
|
|
4044
|
+
"../../node_modules/.pnpm/supports-color@10.0.0/node_modules/supports-color/index.js"() {
|
|
4045
|
+
({ env } = process2__default.default);
|
|
4046
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
4047
|
+
flagForceColor = 0;
|
|
4048
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
4049
|
+
flagForceColor = 1;
|
|
4001
4050
|
}
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
stderr: getSupportLevel(process.stderr)
|
|
4051
|
+
supportsColor = {
|
|
4052
|
+
stdout: createSupportsColor({ isTTY: tty__default.default.isatty(1) }),
|
|
4053
|
+
stderr: createSupportsColor({ isTTY: tty__default.default.isatty(2) })
|
|
4006
4054
|
};
|
|
4055
|
+
supports_color_default = supportsColor;
|
|
4007
4056
|
}
|
|
4008
4057
|
});
|
|
4009
4058
|
|
|
4010
|
-
// ../../node_modules/.pnpm/debug@4.3.
|
|
4059
|
+
// ../../node_modules/.pnpm/debug@4.3.7_supports-color@10.0.0/node_modules/debug/src/node.js
|
|
4011
4060
|
var require_node = __commonJS({
|
|
4012
|
-
"../../node_modules/.pnpm/debug@4.3.
|
|
4013
|
-
var
|
|
4061
|
+
"../../node_modules/.pnpm/debug@4.3.7_supports-color@10.0.0/node_modules/debug/src/node.js"(exports, module) {
|
|
4062
|
+
var tty2 = __require("tty");
|
|
4014
4063
|
var util = __require("util");
|
|
4015
4064
|
exports.init = init;
|
|
4016
4065
|
exports.log = log;
|
|
@@ -4025,8 +4074,8 @@ var require_node = __commonJS({
|
|
|
4025
4074
|
);
|
|
4026
4075
|
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
4027
4076
|
try {
|
|
4028
|
-
const
|
|
4029
|
-
if (
|
|
4077
|
+
const supportsColor2 = (init_supports_color(), __toCommonJS(supports_color_exports));
|
|
4078
|
+
if (supportsColor2 && (supportsColor2.stderr || supportsColor2).level >= 2) {
|
|
4030
4079
|
exports.colors = [
|
|
4031
4080
|
20,
|
|
4032
4081
|
21,
|
|
@@ -4128,7 +4177,7 @@ var require_node = __commonJS({
|
|
|
4128
4177
|
return obj;
|
|
4129
4178
|
}, {});
|
|
4130
4179
|
function useColors() {
|
|
4131
|
-
return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) :
|
|
4180
|
+
return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty2.isatty(process.stderr.fd);
|
|
4132
4181
|
}
|
|
4133
4182
|
function formatArgs(args) {
|
|
4134
4183
|
const { namespace: name, useColors: useColors2 } = this;
|
|
@@ -4181,9 +4230,9 @@ var require_node = __commonJS({
|
|
|
4181
4230
|
}
|
|
4182
4231
|
});
|
|
4183
4232
|
|
|
4184
|
-
// ../../node_modules/.pnpm/debug@4.3.
|
|
4233
|
+
// ../../node_modules/.pnpm/debug@4.3.7_supports-color@10.0.0/node_modules/debug/src/index.js
|
|
4185
4234
|
var require_src = __commonJS({
|
|
4186
|
-
"../../node_modules/.pnpm/debug@4.3.
|
|
4235
|
+
"../../node_modules/.pnpm/debug@4.3.7_supports-color@10.0.0/node_modules/debug/src/index.js"(exports, module) {
|
|
4187
4236
|
if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
|
|
4188
4237
|
module.exports = require_browser();
|
|
4189
4238
|
} else {
|
|
@@ -8693,7 +8742,7 @@ var require_Redis = __commonJS({
|
|
|
8693
8742
|
var lodash_1 = require_lodash3();
|
|
8694
8743
|
var Deque = require_denque();
|
|
8695
8744
|
var debug = (0, utils_1.Debug)("redis");
|
|
8696
|
-
var
|
|
8745
|
+
var Redis4 = class _Redis extends Commander_1.default {
|
|
8697
8746
|
constructor(arg1, arg2, arg3) {
|
|
8698
8747
|
super();
|
|
8699
8748
|
this.status = "wait";
|
|
@@ -9256,12 +9305,12 @@ var require_Redis = __commonJS({
|
|
|
9256
9305
|
}).catch(lodash_1.noop);
|
|
9257
9306
|
}
|
|
9258
9307
|
};
|
|
9259
|
-
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
(0, applyMixin_1.default)(
|
|
9263
|
-
(0, transaction_1.addTransactionSupport)(
|
|
9264
|
-
exports.default =
|
|
9308
|
+
Redis4.Cluster = cluster_1.default;
|
|
9309
|
+
Redis4.Command = Command_1.default;
|
|
9310
|
+
Redis4.defaultOptions = RedisOptions_1.DEFAULT_REDIS_OPTIONS;
|
|
9311
|
+
(0, applyMixin_1.default)(Redis4, events_1.EventEmitter);
|
|
9312
|
+
(0, transaction_1.addTransactionSupport)(Redis4.prototype);
|
|
9313
|
+
exports.default = Redis4;
|
|
9265
9314
|
}
|
|
9266
9315
|
});
|
|
9267
9316
|
|
|
@@ -9459,6 +9508,39 @@ var SimpleQueue = class {
|
|
|
9459
9508
|
throw e;
|
|
9460
9509
|
}
|
|
9461
9510
|
}
|
|
9511
|
+
async enqueueOnce({
|
|
9512
|
+
id,
|
|
9513
|
+
job,
|
|
9514
|
+
item,
|
|
9515
|
+
attempt,
|
|
9516
|
+
availableAt,
|
|
9517
|
+
visibilityTimeoutMs
|
|
9518
|
+
}) {
|
|
9519
|
+
if (!id) {
|
|
9520
|
+
throw new Error("enqueueOnce requires an id");
|
|
9521
|
+
}
|
|
9522
|
+
try {
|
|
9523
|
+
const score = availableAt ? availableAt.getTime() : Date.now();
|
|
9524
|
+
const deduplicationKey = nanoid();
|
|
9525
|
+
const serializedItem = JSON.stringify({
|
|
9526
|
+
job,
|
|
9527
|
+
item,
|
|
9528
|
+
visibilityTimeoutMs,
|
|
9529
|
+
attempt,
|
|
9530
|
+
deduplicationKey
|
|
9531
|
+
});
|
|
9532
|
+
const result = await this.redis.enqueueItemOnce(`queue`, `items`, id, score, serializedItem);
|
|
9533
|
+
return result === 1;
|
|
9534
|
+
} catch (e) {
|
|
9535
|
+
this.logger.error(`SimpleQueue ${this.name}.enqueueOnce(): error enqueuing`, {
|
|
9536
|
+
queue: this.name,
|
|
9537
|
+
error: e,
|
|
9538
|
+
id,
|
|
9539
|
+
item
|
|
9540
|
+
});
|
|
9541
|
+
throw e;
|
|
9542
|
+
}
|
|
9543
|
+
}
|
|
9462
9544
|
async dequeue(count = 1) {
|
|
9463
9545
|
const now = Date.now();
|
|
9464
9546
|
try {
|
|
@@ -9481,7 +9563,8 @@ var SimpleQueue = class {
|
|
|
9481
9563
|
id,
|
|
9482
9564
|
item: parsedItem,
|
|
9483
9565
|
job: parsedItem.job,
|
|
9484
|
-
timestamp
|
|
9566
|
+
timestamp,
|
|
9567
|
+
availableJobs: Object.keys(this.schema)
|
|
9485
9568
|
});
|
|
9486
9569
|
continue;
|
|
9487
9570
|
}
|
|
@@ -9773,6 +9856,25 @@ var SimpleQueue = class {
|
|
|
9773
9856
|
return 1
|
|
9774
9857
|
`
|
|
9775
9858
|
});
|
|
9859
|
+
this.redis.defineCommand("enqueueItemOnce", {
|
|
9860
|
+
numberOfKeys: 2,
|
|
9861
|
+
lua: `
|
|
9862
|
+
local queue = KEYS[1]
|
|
9863
|
+
local items = KEYS[2]
|
|
9864
|
+
local id = ARGV[1]
|
|
9865
|
+
local score = ARGV[2]
|
|
9866
|
+
local serializedItem = ARGV[3]
|
|
9867
|
+
|
|
9868
|
+
-- Only add if not exists
|
|
9869
|
+
local added = redis.call('HSETNX', items, id, serializedItem)
|
|
9870
|
+
if added == 1 then
|
|
9871
|
+
redis.call('ZADD', queue, 'NX', score, id)
|
|
9872
|
+
return 1
|
|
9873
|
+
else
|
|
9874
|
+
return 0
|
|
9875
|
+
end
|
|
9876
|
+
`
|
|
9877
|
+
});
|
|
9776
9878
|
}
|
|
9777
9879
|
};
|
|
9778
9880
|
|
|
@@ -10129,6 +10231,173 @@ var BaseContext = (
|
|
|
10129
10231
|
);
|
|
10130
10232
|
var ROOT_CONTEXT = new BaseContext();
|
|
10131
10233
|
|
|
10234
|
+
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/metrics/NoopMeter.js
|
|
10235
|
+
var __extends = /* @__PURE__ */ function() {
|
|
10236
|
+
var extendStatics = function(d, b) {
|
|
10237
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
10238
|
+
d2.__proto__ = b2;
|
|
10239
|
+
} || function(d2, b2) {
|
|
10240
|
+
for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p];
|
|
10241
|
+
};
|
|
10242
|
+
return extendStatics(d, b);
|
|
10243
|
+
};
|
|
10244
|
+
return function(d, b) {
|
|
10245
|
+
if (typeof b !== "function" && b !== null)
|
|
10246
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
10247
|
+
extendStatics(d, b);
|
|
10248
|
+
function __() {
|
|
10249
|
+
this.constructor = d;
|
|
10250
|
+
}
|
|
10251
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
10252
|
+
};
|
|
10253
|
+
}();
|
|
10254
|
+
var NoopMeter = (
|
|
10255
|
+
/** @class */
|
|
10256
|
+
function() {
|
|
10257
|
+
function NoopMeter2() {
|
|
10258
|
+
}
|
|
10259
|
+
NoopMeter2.prototype.createGauge = function(_name, _options) {
|
|
10260
|
+
return NOOP_GAUGE_METRIC;
|
|
10261
|
+
};
|
|
10262
|
+
NoopMeter2.prototype.createHistogram = function(_name, _options) {
|
|
10263
|
+
return NOOP_HISTOGRAM_METRIC;
|
|
10264
|
+
};
|
|
10265
|
+
NoopMeter2.prototype.createCounter = function(_name, _options) {
|
|
10266
|
+
return NOOP_COUNTER_METRIC;
|
|
10267
|
+
};
|
|
10268
|
+
NoopMeter2.prototype.createUpDownCounter = function(_name, _options) {
|
|
10269
|
+
return NOOP_UP_DOWN_COUNTER_METRIC;
|
|
10270
|
+
};
|
|
10271
|
+
NoopMeter2.prototype.createObservableGauge = function(_name, _options) {
|
|
10272
|
+
return NOOP_OBSERVABLE_GAUGE_METRIC;
|
|
10273
|
+
};
|
|
10274
|
+
NoopMeter2.prototype.createObservableCounter = function(_name, _options) {
|
|
10275
|
+
return NOOP_OBSERVABLE_COUNTER_METRIC;
|
|
10276
|
+
};
|
|
10277
|
+
NoopMeter2.prototype.createObservableUpDownCounter = function(_name, _options) {
|
|
10278
|
+
return NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC;
|
|
10279
|
+
};
|
|
10280
|
+
NoopMeter2.prototype.addBatchObservableCallback = function(_callback, _observables) {
|
|
10281
|
+
};
|
|
10282
|
+
NoopMeter2.prototype.removeBatchObservableCallback = function(_callback) {
|
|
10283
|
+
};
|
|
10284
|
+
return NoopMeter2;
|
|
10285
|
+
}()
|
|
10286
|
+
);
|
|
10287
|
+
var NoopMetric = (
|
|
10288
|
+
/** @class */
|
|
10289
|
+
/* @__PURE__ */ function() {
|
|
10290
|
+
function NoopMetric2() {
|
|
10291
|
+
}
|
|
10292
|
+
return NoopMetric2;
|
|
10293
|
+
}()
|
|
10294
|
+
);
|
|
10295
|
+
var NoopCounterMetric = (
|
|
10296
|
+
/** @class */
|
|
10297
|
+
function(_super) {
|
|
10298
|
+
__extends(NoopCounterMetric2, _super);
|
|
10299
|
+
function NoopCounterMetric2() {
|
|
10300
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10301
|
+
}
|
|
10302
|
+
NoopCounterMetric2.prototype.add = function(_value, _attributes) {
|
|
10303
|
+
};
|
|
10304
|
+
return NoopCounterMetric2;
|
|
10305
|
+
}(NoopMetric)
|
|
10306
|
+
);
|
|
10307
|
+
var NoopUpDownCounterMetric = (
|
|
10308
|
+
/** @class */
|
|
10309
|
+
function(_super) {
|
|
10310
|
+
__extends(NoopUpDownCounterMetric2, _super);
|
|
10311
|
+
function NoopUpDownCounterMetric2() {
|
|
10312
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10313
|
+
}
|
|
10314
|
+
NoopUpDownCounterMetric2.prototype.add = function(_value, _attributes) {
|
|
10315
|
+
};
|
|
10316
|
+
return NoopUpDownCounterMetric2;
|
|
10317
|
+
}(NoopMetric)
|
|
10318
|
+
);
|
|
10319
|
+
var NoopGaugeMetric = (
|
|
10320
|
+
/** @class */
|
|
10321
|
+
function(_super) {
|
|
10322
|
+
__extends(NoopGaugeMetric2, _super);
|
|
10323
|
+
function NoopGaugeMetric2() {
|
|
10324
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10325
|
+
}
|
|
10326
|
+
NoopGaugeMetric2.prototype.record = function(_value, _attributes) {
|
|
10327
|
+
};
|
|
10328
|
+
return NoopGaugeMetric2;
|
|
10329
|
+
}(NoopMetric)
|
|
10330
|
+
);
|
|
10331
|
+
var NoopHistogramMetric = (
|
|
10332
|
+
/** @class */
|
|
10333
|
+
function(_super) {
|
|
10334
|
+
__extends(NoopHistogramMetric2, _super);
|
|
10335
|
+
function NoopHistogramMetric2() {
|
|
10336
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10337
|
+
}
|
|
10338
|
+
NoopHistogramMetric2.prototype.record = function(_value, _attributes) {
|
|
10339
|
+
};
|
|
10340
|
+
return NoopHistogramMetric2;
|
|
10341
|
+
}(NoopMetric)
|
|
10342
|
+
);
|
|
10343
|
+
var NoopObservableMetric = (
|
|
10344
|
+
/** @class */
|
|
10345
|
+
function() {
|
|
10346
|
+
function NoopObservableMetric2() {
|
|
10347
|
+
}
|
|
10348
|
+
NoopObservableMetric2.prototype.addCallback = function(_callback) {
|
|
10349
|
+
};
|
|
10350
|
+
NoopObservableMetric2.prototype.removeCallback = function(_callback) {
|
|
10351
|
+
};
|
|
10352
|
+
return NoopObservableMetric2;
|
|
10353
|
+
}()
|
|
10354
|
+
);
|
|
10355
|
+
var NoopObservableCounterMetric = (
|
|
10356
|
+
/** @class */
|
|
10357
|
+
function(_super) {
|
|
10358
|
+
__extends(NoopObservableCounterMetric2, _super);
|
|
10359
|
+
function NoopObservableCounterMetric2() {
|
|
10360
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10361
|
+
}
|
|
10362
|
+
return NoopObservableCounterMetric2;
|
|
10363
|
+
}(NoopObservableMetric)
|
|
10364
|
+
);
|
|
10365
|
+
var NoopObservableGaugeMetric = (
|
|
10366
|
+
/** @class */
|
|
10367
|
+
function(_super) {
|
|
10368
|
+
__extends(NoopObservableGaugeMetric2, _super);
|
|
10369
|
+
function NoopObservableGaugeMetric2() {
|
|
10370
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10371
|
+
}
|
|
10372
|
+
return NoopObservableGaugeMetric2;
|
|
10373
|
+
}(NoopObservableMetric)
|
|
10374
|
+
);
|
|
10375
|
+
var NoopObservableUpDownCounterMetric = (
|
|
10376
|
+
/** @class */
|
|
10377
|
+
function(_super) {
|
|
10378
|
+
__extends(NoopObservableUpDownCounterMetric2, _super);
|
|
10379
|
+
function NoopObservableUpDownCounterMetric2() {
|
|
10380
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
10381
|
+
}
|
|
10382
|
+
return NoopObservableUpDownCounterMetric2;
|
|
10383
|
+
}(NoopObservableMetric)
|
|
10384
|
+
);
|
|
10385
|
+
var NOOP_METER = new NoopMeter();
|
|
10386
|
+
var NOOP_COUNTER_METRIC = new NoopCounterMetric();
|
|
10387
|
+
var NOOP_GAUGE_METRIC = new NoopGaugeMetric();
|
|
10388
|
+
var NOOP_HISTOGRAM_METRIC = new NoopHistogramMetric();
|
|
10389
|
+
var NOOP_UP_DOWN_COUNTER_METRIC = new NoopUpDownCounterMetric();
|
|
10390
|
+
var NOOP_OBSERVABLE_COUNTER_METRIC = new NoopObservableCounterMetric();
|
|
10391
|
+
var NOOP_OBSERVABLE_GAUGE_METRIC = new NoopObservableGaugeMetric();
|
|
10392
|
+
var NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC = new NoopObservableUpDownCounterMetric();
|
|
10393
|
+
|
|
10394
|
+
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/metrics/Metric.js
|
|
10395
|
+
var ValueType;
|
|
10396
|
+
(function(ValueType2) {
|
|
10397
|
+
ValueType2[ValueType2["INT"] = 0] = "INT";
|
|
10398
|
+
ValueType2[ValueType2["DOUBLE"] = 1] = "DOUBLE";
|
|
10399
|
+
})(ValueType || (ValueType = {}));
|
|
10400
|
+
|
|
10132
10401
|
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/context/NoopContextManager.js
|
|
10133
10402
|
var __read3 = function(o, n) {
|
|
10134
10403
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
@@ -10491,8 +10760,54 @@ var SpanStatusCode;
|
|
|
10491
10760
|
SpanStatusCode2[SpanStatusCode2["ERROR"] = 2] = "ERROR";
|
|
10492
10761
|
})(SpanStatusCode || (SpanStatusCode = {}));
|
|
10493
10762
|
|
|
10763
|
+
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/metrics/NoopMeterProvider.js
|
|
10764
|
+
var NoopMeterProvider = (
|
|
10765
|
+
/** @class */
|
|
10766
|
+
function() {
|
|
10767
|
+
function NoopMeterProvider2() {
|
|
10768
|
+
}
|
|
10769
|
+
NoopMeterProvider2.prototype.getMeter = function(_name, _version, _options) {
|
|
10770
|
+
return NOOP_METER;
|
|
10771
|
+
};
|
|
10772
|
+
return NoopMeterProvider2;
|
|
10773
|
+
}()
|
|
10774
|
+
);
|
|
10775
|
+
var NOOP_METER_PROVIDER = new NoopMeterProvider();
|
|
10776
|
+
|
|
10777
|
+
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/api/metrics.js
|
|
10778
|
+
var API_NAME3 = "metrics";
|
|
10779
|
+
var MetricsAPI = (
|
|
10780
|
+
/** @class */
|
|
10781
|
+
function() {
|
|
10782
|
+
function MetricsAPI2() {
|
|
10783
|
+
}
|
|
10784
|
+
MetricsAPI2.getInstance = function() {
|
|
10785
|
+
if (!this._instance) {
|
|
10786
|
+
this._instance = new MetricsAPI2();
|
|
10787
|
+
}
|
|
10788
|
+
return this._instance;
|
|
10789
|
+
};
|
|
10790
|
+
MetricsAPI2.prototype.setGlobalMeterProvider = function(provider) {
|
|
10791
|
+
return registerGlobal(API_NAME3, provider, DiagAPI.instance());
|
|
10792
|
+
};
|
|
10793
|
+
MetricsAPI2.prototype.getMeterProvider = function() {
|
|
10794
|
+
return getGlobal(API_NAME3) || NOOP_METER_PROVIDER;
|
|
10795
|
+
};
|
|
10796
|
+
MetricsAPI2.prototype.getMeter = function(name, version, options) {
|
|
10797
|
+
return this.getMeterProvider().getMeter(name, version, options);
|
|
10798
|
+
};
|
|
10799
|
+
MetricsAPI2.prototype.disable = function() {
|
|
10800
|
+
unregisterGlobal(API_NAME3, DiagAPI.instance());
|
|
10801
|
+
};
|
|
10802
|
+
return MetricsAPI2;
|
|
10803
|
+
}()
|
|
10804
|
+
);
|
|
10805
|
+
|
|
10806
|
+
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/metrics-api.js
|
|
10807
|
+
var metrics = MetricsAPI.getInstance();
|
|
10808
|
+
|
|
10494
10809
|
// ../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/api/trace.js
|
|
10495
|
-
var
|
|
10810
|
+
var API_NAME4 = "trace";
|
|
10496
10811
|
var TraceAPI = (
|
|
10497
10812
|
/** @class */
|
|
10498
10813
|
function() {
|
|
@@ -10514,20 +10829,20 @@ var TraceAPI = (
|
|
|
10514
10829
|
return this._instance;
|
|
10515
10830
|
};
|
|
10516
10831
|
TraceAPI2.prototype.setGlobalTracerProvider = function(provider) {
|
|
10517
|
-
var success = registerGlobal(
|
|
10832
|
+
var success = registerGlobal(API_NAME4, this._proxyTracerProvider, DiagAPI.instance());
|
|
10518
10833
|
if (success) {
|
|
10519
10834
|
this._proxyTracerProvider.setDelegate(provider);
|
|
10520
10835
|
}
|
|
10521
10836
|
return success;
|
|
10522
10837
|
};
|
|
10523
10838
|
TraceAPI2.prototype.getTracerProvider = function() {
|
|
10524
|
-
return getGlobal(
|
|
10839
|
+
return getGlobal(API_NAME4) || this._proxyTracerProvider;
|
|
10525
10840
|
};
|
|
10526
10841
|
TraceAPI2.prototype.getTracer = function(name, version) {
|
|
10527
10842
|
return this.getTracerProvider().getTracer(name, version);
|
|
10528
10843
|
};
|
|
10529
10844
|
TraceAPI2.prototype.disable = function() {
|
|
10530
|
-
unregisterGlobal(
|
|
10845
|
+
unregisterGlobal(API_NAME4, DiagAPI.instance());
|
|
10531
10846
|
this._proxyTracerProvider = new ProxyTracerProvider();
|
|
10532
10847
|
};
|
|
10533
10848
|
return TraceAPI2;
|
|
@@ -10693,6 +11008,8 @@ function validateConcurrency(concurrency) {
|
|
|
10693
11008
|
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
10694
11009
|
}
|
|
10695
11010
|
}
|
|
11011
|
+
|
|
11012
|
+
// src/worker.ts
|
|
10696
11013
|
var defaultRetrySettings = {
|
|
10697
11014
|
maxAttempts: 12,
|
|
10698
11015
|
factor: 2,
|
|
@@ -10707,6 +11024,7 @@ var Worker = class _Worker {
|
|
|
10707
11024
|
this.options = options;
|
|
10708
11025
|
this.logger = options.logger ?? new logger$1.Logger("Worker", "debug");
|
|
10709
11026
|
this.tracer = options.tracer ?? trace.getTracer(options.name);
|
|
11027
|
+
this.meter = options.meter ?? metrics.getMeter(options.name);
|
|
10710
11028
|
this.shutdownTimeoutMs = options.shutdownTimeoutMs ?? 6e4;
|
|
10711
11029
|
const schema = Object.fromEntries(
|
|
10712
11030
|
Object.entries(this.options.catalog).map(([key, value]) => [key, value.schema])
|
|
@@ -10721,56 +11039,47 @@ var Worker = class _Worker {
|
|
|
10721
11039
|
const { workers = 1, tasksPerWorker = 1, limit = 10 } = options.concurrency ?? {};
|
|
10722
11040
|
this.concurrency = { workers, tasksPerWorker, limit };
|
|
10723
11041
|
this.limiter = pLimit(this.concurrency.limit);
|
|
10724
|
-
this.
|
|
10725
|
-
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
this.metrics.enqueueDuration = new promClient.Histogram({
|
|
10729
|
-
name: "redis_worker_enqueue_duration_seconds",
|
|
10730
|
-
help: "The duration of enqueue operations",
|
|
10731
|
-
labelNames: ["worker_name", "job_type", "has_available_at"],
|
|
10732
|
-
buckets: [1e-3, 5e-3, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1],
|
|
10733
|
-
registers: [this.metrics.register]
|
|
10734
|
-
});
|
|
10735
|
-
this.metrics.dequeueDuration = new promClient.Histogram({
|
|
10736
|
-
name: "redis_worker_dequeue_duration_seconds",
|
|
10737
|
-
help: "The duration of dequeue operations",
|
|
10738
|
-
labelNames: ["worker_name", "worker_id", "task_count"],
|
|
10739
|
-
buckets: [1e-3, 5e-3, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1],
|
|
10740
|
-
registers: [this.metrics.register]
|
|
10741
|
-
});
|
|
10742
|
-
this.metrics.jobDuration = new promClient.Histogram({
|
|
10743
|
-
name: "redis_worker_job_duration_seconds",
|
|
10744
|
-
help: "The duration of job operations",
|
|
10745
|
-
labelNames: ["worker_name", "worker_id", "batch_size", "job_type", "attempt"],
|
|
10746
|
-
// use different buckets here as jobs can take a while to run
|
|
10747
|
-
buckets: [0.1, 0.25, 0.5, 1, 2.5, 5, 10, 20, 30, 45, 60],
|
|
10748
|
-
registers: [this.metrics.register]
|
|
10749
|
-
});
|
|
10750
|
-
this.metrics.ackDuration = new promClient.Histogram({
|
|
10751
|
-
name: "redis_worker_ack_duration_seconds",
|
|
10752
|
-
help: "The duration of ack operations",
|
|
10753
|
-
labelNames: ["worker_name"],
|
|
10754
|
-
buckets: [1e-3, 5e-3, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1],
|
|
10755
|
-
registers: [this.metrics.register]
|
|
10756
|
-
});
|
|
10757
|
-
this.metrics.redriveDuration = new promClient.Histogram({
|
|
10758
|
-
name: "redis_worker_redrive_duration_seconds",
|
|
10759
|
-
help: "The duration of redrive operations",
|
|
10760
|
-
labelNames: ["worker_name"],
|
|
10761
|
-
buckets: [1e-3, 5e-3, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1],
|
|
10762
|
-
registers: [this.metrics.register]
|
|
10763
|
-
});
|
|
10764
|
-
this.metrics.rescheduleDuration = new promClient.Histogram({
|
|
10765
|
-
name: "redis_worker_reschedule_duration_seconds",
|
|
10766
|
-
help: "The duration of reschedule operations",
|
|
10767
|
-
labelNames: ["worker_name"],
|
|
10768
|
-
buckets: [1e-3, 5e-3, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1],
|
|
10769
|
-
registers: [this.metrics.register]
|
|
11042
|
+
const masterQueueObservableGauge = this.meter.createObservableGauge("redis_worker.queue.size", {
|
|
11043
|
+
description: "The number of items in the queue",
|
|
11044
|
+
unit: "items",
|
|
11045
|
+
valueType: ValueType.INT
|
|
10770
11046
|
});
|
|
11047
|
+
masterQueueObservableGauge.addCallback(this.#updateQueueSizeMetric.bind(this));
|
|
11048
|
+
const deadLetterQueueObservableGauge = this.meter.createObservableGauge(
|
|
11049
|
+
"redis_worker.queue.dead_letter_size",
|
|
11050
|
+
{
|
|
11051
|
+
description: "The number of items in the dead letter queue",
|
|
11052
|
+
unit: "items",
|
|
11053
|
+
valueType: ValueType.INT
|
|
11054
|
+
}
|
|
11055
|
+
);
|
|
11056
|
+
deadLetterQueueObservableGauge.addCallback(this.#updateDeadLetterQueueSizeMetric.bind(this));
|
|
11057
|
+
const concurrencyLimitActiveObservableGauge = this.meter.createObservableGauge(
|
|
11058
|
+
"redis_worker.concurrency.active",
|
|
11059
|
+
{
|
|
11060
|
+
description: "The number of active workers",
|
|
11061
|
+
unit: "workers",
|
|
11062
|
+
valueType: ValueType.INT
|
|
11063
|
+
}
|
|
11064
|
+
);
|
|
11065
|
+
concurrencyLimitActiveObservableGauge.addCallback(
|
|
11066
|
+
this.#updateConcurrencyLimitActiveMetric.bind(this)
|
|
11067
|
+
);
|
|
11068
|
+
const concurrencyLimitPendingObservableGauge = this.meter.createObservableGauge(
|
|
11069
|
+
"redis_worker.concurrency.pending",
|
|
11070
|
+
{
|
|
11071
|
+
description: "The number of pending workers",
|
|
11072
|
+
unit: "workers",
|
|
11073
|
+
valueType: ValueType.INT
|
|
11074
|
+
}
|
|
11075
|
+
);
|
|
11076
|
+
concurrencyLimitPendingObservableGauge.addCallback(
|
|
11077
|
+
this.#updateConcurrencyLimitPendingMetric.bind(this)
|
|
11078
|
+
);
|
|
10771
11079
|
}
|
|
10772
11080
|
subscriber;
|
|
10773
11081
|
tracer;
|
|
11082
|
+
meter;
|
|
10774
11083
|
metrics = {};
|
|
10775
11084
|
queue;
|
|
10776
11085
|
jobs;
|
|
@@ -10781,6 +11090,28 @@ var Worker = class _Worker {
|
|
|
10781
11090
|
shutdownTimeoutMs;
|
|
10782
11091
|
// The p-limit limiter to control overall concurrency.
|
|
10783
11092
|
limiter;
|
|
11093
|
+
async #updateQueueSizeMetric(observableResult) {
|
|
11094
|
+
const queueSize = await this.queue.size();
|
|
11095
|
+
observableResult.observe(queueSize, {
|
|
11096
|
+
worker_name: this.options.name
|
|
11097
|
+
});
|
|
11098
|
+
}
|
|
11099
|
+
async #updateDeadLetterQueueSizeMetric(observableResult) {
|
|
11100
|
+
const deadLetterQueueSize = await this.queue.sizeOfDeadLetterQueue();
|
|
11101
|
+
observableResult.observe(deadLetterQueueSize, {
|
|
11102
|
+
worker_name: this.options.name
|
|
11103
|
+
});
|
|
11104
|
+
}
|
|
11105
|
+
async #updateConcurrencyLimitActiveMetric(observableResult) {
|
|
11106
|
+
observableResult.observe(this.limiter.activeCount, {
|
|
11107
|
+
worker_name: this.options.name
|
|
11108
|
+
});
|
|
11109
|
+
}
|
|
11110
|
+
async #updateConcurrencyLimitPendingMetric(observableResult) {
|
|
11111
|
+
observableResult.observe(this.limiter.pendingCount, {
|
|
11112
|
+
worker_name: this.options.name
|
|
11113
|
+
});
|
|
11114
|
+
}
|
|
10784
11115
|
start() {
|
|
10785
11116
|
const { workers, tasksPerWorker } = this.concurrency;
|
|
10786
11117
|
for (let i = 0; i < workers; i++) {
|
|
@@ -10848,6 +11179,56 @@ var Worker = class _Worker {
|
|
|
10848
11179
|
}
|
|
10849
11180
|
);
|
|
10850
11181
|
}
|
|
11182
|
+
/**
|
|
11183
|
+
* Enqueues a job for processing once. If the job is already in the queue, it will be ignored.
|
|
11184
|
+
* @param options - The enqueue options.
|
|
11185
|
+
* @param options.id - Required unique identifier for the job.
|
|
11186
|
+
* @param options.job - The job type from the worker catalog.
|
|
11187
|
+
* @param options.payload - The job payload that matches the schema defined in the catalog.
|
|
11188
|
+
* @param options.visibilityTimeoutMs - Optional visibility timeout in milliseconds. Defaults to value from catalog.
|
|
11189
|
+
* @param options.availableAt - Optional date when the job should become available for processing. Defaults to now.
|
|
11190
|
+
* @returns A promise that resolves when the job is enqueued.
|
|
11191
|
+
*/
|
|
11192
|
+
enqueueOnce({
|
|
11193
|
+
id,
|
|
11194
|
+
job,
|
|
11195
|
+
payload,
|
|
11196
|
+
visibilityTimeoutMs,
|
|
11197
|
+
availableAt
|
|
11198
|
+
}) {
|
|
11199
|
+
return startSpan(
|
|
11200
|
+
this.tracer,
|
|
11201
|
+
"enqueueOnce",
|
|
11202
|
+
async (span) => {
|
|
11203
|
+
const timeout = visibilityTimeoutMs ?? this.options.catalog[job]?.visibilityTimeoutMs;
|
|
11204
|
+
if (!timeout) {
|
|
11205
|
+
throw new Error(`No visibility timeout found for job ${String(job)} with id ${id}`);
|
|
11206
|
+
}
|
|
11207
|
+
span.setAttribute("job_visibility_timeout_ms", timeout);
|
|
11208
|
+
return this.withHistogram(
|
|
11209
|
+
this.metrics.enqueueDuration,
|
|
11210
|
+
this.queue.enqueueOnce({
|
|
11211
|
+
id,
|
|
11212
|
+
job,
|
|
11213
|
+
item: payload,
|
|
11214
|
+
visibilityTimeoutMs: timeout,
|
|
11215
|
+
availableAt
|
|
11216
|
+
}),
|
|
11217
|
+
{
|
|
11218
|
+
job_type: String(job),
|
|
11219
|
+
has_available_at: availableAt ? "true" : "false"
|
|
11220
|
+
}
|
|
11221
|
+
);
|
|
11222
|
+
},
|
|
11223
|
+
{
|
|
11224
|
+
kind: SpanKind.PRODUCER,
|
|
11225
|
+
attributes: {
|
|
11226
|
+
job_type: String(job),
|
|
11227
|
+
job_id: id
|
|
11228
|
+
}
|
|
11229
|
+
}
|
|
11230
|
+
);
|
|
11231
|
+
}
|
|
10851
11232
|
/**
|
|
10852
11233
|
* Reschedules an existing job to a new available date.
|
|
10853
11234
|
* If the job isn't in the queue, it will be ignored.
|
|
@@ -11032,14 +11413,15 @@ var Worker = class _Worker {
|
|
|
11032
11413
|
});
|
|
11033
11414
|
}
|
|
11034
11415
|
async withHistogram(histogram, promise, labels) {
|
|
11035
|
-
if (!histogram
|
|
11416
|
+
if (!histogram) {
|
|
11036
11417
|
return promise;
|
|
11037
11418
|
}
|
|
11038
|
-
const
|
|
11419
|
+
const start = Date.now();
|
|
11039
11420
|
try {
|
|
11040
11421
|
return await promise;
|
|
11041
11422
|
} finally {
|
|
11042
|
-
|
|
11423
|
+
const duration = (Date.now() - start) / 1e3;
|
|
11424
|
+
histogram.record(duration, { worker_name: this.options.name, ...labels });
|
|
11043
11425
|
}
|
|
11044
11426
|
}
|
|
11045
11427
|
// A simple helper to delay for a given number of milliseconds.
|