nmtjs 0.15.0-beta.2 → 0.15.0-beta.20
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/cli.d.ts +2 -0
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +51 -0
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -0
- package/dist/entrypoints/cli.d.ts +1 -0
- package/dist/entrypoints/cli.js +1 -0
- package/dist/entrypoints/cli.js.map +1 -0
- package/dist/entrypoints/main.d.ts +5 -0
- package/dist/entrypoints/main.js +83 -15
- package/dist/entrypoints/main.js.map +1 -0
- package/dist/entrypoints/thread.d.ts +14 -0
- package/dist/entrypoints/thread.js +130 -24
- package/dist/entrypoints/thread.js.map +1 -0
- package/dist/entrypoints/worker.d.ts +3 -0
- package/dist/entrypoints/worker.js +4 -3
- package/dist/entrypoints/worker.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/{_exports/index.js → index.js} +9 -5
- package/dist/index.js.map +1 -0
- package/dist/resolver.d.ts +2 -0
- package/dist/resolver.js +1 -0
- package/dist/resolver.js.map +1 -0
- package/dist/runtime/application/api/api.d.ts +49 -0
- package/dist/runtime/application/api/api.js +193 -0
- package/dist/runtime/application/api/api.js.map +1 -0
- package/dist/runtime/application/api/constants.d.ts +14 -0
- package/dist/runtime/application/api/constants.js +8 -0
- package/dist/runtime/application/api/constants.js.map +1 -0
- package/dist/runtime/application/api/filters.d.ts +14 -0
- package/dist/runtime/application/api/filters.js +11 -0
- package/dist/runtime/application/api/filters.js.map +1 -0
- package/dist/runtime/application/api/guards.d.ts +13 -0
- package/dist/runtime/application/api/guards.js +8 -0
- package/dist/runtime/application/api/guards.js.map +1 -0
- package/dist/runtime/application/api/index.d.ts +8 -0
- package/dist/runtime/application/api/index.js +9 -0
- package/dist/runtime/application/api/index.js.map +1 -0
- package/dist/runtime/application/api/middlewares.d.ts +14 -0
- package/dist/runtime/application/api/middlewares.js +12 -0
- package/dist/runtime/application/api/middlewares.js.map +1 -0
- package/dist/runtime/application/api/procedure.d.ts +67 -0
- package/dist/runtime/application/api/procedure.js +50 -0
- package/dist/runtime/application/api/procedure.js.map +1 -0
- package/dist/runtime/application/api/router.d.ts +71 -0
- package/dist/runtime/application/api/router.js +51 -0
- package/dist/runtime/application/api/router.js.map +1 -0
- package/dist/runtime/application/api/types.d.ts +32 -0
- package/dist/runtime/application/api/types.js +2 -0
- package/dist/runtime/application/api/types.js.map +1 -0
- package/dist/runtime/application/config.d.ts +26 -0
- package/dist/runtime/application/config.js +21 -0
- package/dist/runtime/application/config.js.map +1 -0
- package/dist/runtime/application/constants.d.ts +2 -0
- package/dist/runtime/application/constants.js +2 -0
- package/dist/runtime/application/constants.js.map +1 -0
- package/dist/runtime/application/hook.d.ts +19 -0
- package/dist/runtime/application/hook.js +11 -0
- package/dist/runtime/application/hook.js.map +1 -0
- package/dist/runtime/application/hooks.d.ts +3 -0
- package/dist/runtime/application/hooks.js +4 -0
- package/dist/runtime/application/hooks.js.map +1 -0
- package/dist/runtime/application/index.d.ts +5 -0
- package/dist/runtime/application/index.js +6 -0
- package/dist/runtime/application/index.js.map +1 -0
- package/dist/runtime/constants.d.ts +8 -0
- package/dist/runtime/constants.js +5 -0
- package/dist/runtime/constants.js.map +1 -0
- package/dist/runtime/core/hooks.d.ts +4 -0
- package/dist/runtime/core/hooks.js +4 -0
- package/dist/runtime/core/hooks.js.map +1 -0
- package/dist/runtime/core/plugin.d.ts +8 -0
- package/dist/runtime/core/plugin.js +4 -0
- package/dist/runtime/core/plugin.js.map +1 -0
- package/dist/runtime/core/runtime.d.ts +27 -0
- package/dist/runtime/core/runtime.js +81 -0
- package/dist/runtime/core/runtime.js.map +1 -0
- package/dist/runtime/enums.d.ts +21 -0
- package/dist/runtime/enums.js +26 -0
- package/dist/runtime/enums.js.map +1 -0
- package/dist/runtime/index.d.ts +21 -0
- package/dist/runtime/index.js +22 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/injectables.d.ts +23 -0
- package/dist/runtime/injectables.js +20 -0
- package/dist/runtime/injectables.js.map +1 -0
- package/dist/runtime/jobs/job.d.ts +132 -0
- package/dist/runtime/jobs/job.js +68 -0
- package/dist/runtime/jobs/job.js.map +1 -0
- package/dist/runtime/jobs/manager.d.ts +103 -0
- package/dist/runtime/jobs/manager.js +200 -0
- package/dist/runtime/jobs/manager.js.map +1 -0
- package/dist/runtime/jobs/router.d.ts +251 -0
- package/dist/runtime/jobs/router.js +396 -0
- package/dist/runtime/jobs/router.js.map +1 -0
- package/dist/runtime/jobs/runner.d.ts +64 -0
- package/dist/runtime/jobs/runner.js +256 -0
- package/dist/runtime/jobs/runner.js.map +1 -0
- package/dist/runtime/jobs/step.d.ts +22 -0
- package/dist/runtime/jobs/step.js +18 -0
- package/dist/runtime/jobs/step.js.map +1 -0
- package/dist/runtime/jobs/ui.d.ts +3 -0
- package/dist/runtime/jobs/ui.js +17 -0
- package/dist/runtime/jobs/ui.js.map +1 -0
- package/dist/runtime/pubsub/manager.d.ts +48 -0
- package/dist/runtime/pubsub/manager.js +119 -0
- package/dist/runtime/pubsub/manager.js.map +1 -0
- package/dist/runtime/pubsub/redis.d.ts +16 -0
- package/dist/runtime/pubsub/redis.js +98 -0
- package/dist/runtime/pubsub/redis.js.map +1 -0
- package/dist/runtime/scheduler/index.d.ts +22 -0
- package/dist/runtime/scheduler/index.js +20 -0
- package/dist/runtime/scheduler/index.js.map +1 -0
- package/dist/runtime/server/applications.d.ts +52 -0
- package/dist/runtime/server/applications.js +133 -0
- package/dist/runtime/server/applications.js.map +1 -0
- package/dist/runtime/server/config.d.ts +121 -0
- package/dist/runtime/server/config.js +33 -0
- package/dist/runtime/server/config.js.map +1 -0
- package/dist/runtime/server/jobs.d.ts +41 -0
- package/dist/runtime/server/jobs.js +181 -0
- package/dist/runtime/server/jobs.js.map +1 -0
- package/dist/runtime/server/pool.d.ts +54 -0
- package/dist/runtime/server/pool.js +194 -0
- package/dist/runtime/server/pool.js.map +1 -0
- package/dist/runtime/server/proxy.d.ts +21 -0
- package/dist/runtime/server/proxy.js +79 -0
- package/dist/runtime/server/proxy.js.map +1 -0
- package/dist/runtime/server/server.d.ts +53 -0
- package/dist/runtime/server/server.js +90 -0
- package/dist/runtime/server/server.js.map +1 -0
- package/dist/runtime/store/index.d.ts +3 -0
- package/dist/runtime/store/index.js +23 -0
- package/dist/runtime/store/index.js.map +1 -0
- package/dist/runtime/types.d.ts +103 -0
- package/dist/runtime/types.js +2 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/runtime/workers/application.d.ts +47 -0
- package/dist/runtime/workers/application.js +162 -0
- package/dist/runtime/workers/application.js.map +1 -0
- package/dist/runtime/workers/base.d.ts +16 -0
- package/dist/runtime/workers/base.js +46 -0
- package/dist/runtime/workers/base.js.map +1 -0
- package/dist/runtime/workers/cli.d.ts +1 -0
- package/dist/runtime/workers/cli.js +2 -0
- package/dist/runtime/workers/cli.js.map +1 -0
- package/dist/runtime/workers/job.d.ts +20 -0
- package/dist/runtime/workers/job.js +172 -0
- package/dist/runtime/workers/job.js.map +1 -0
- package/dist/typings.d.ts +5 -0
- package/dist/typings.js +4 -3
- package/dist/typings.js.map +1 -0
- package/dist/vite/builder.d.ts +5 -0
- package/dist/vite/builder.js +5 -1
- package/dist/vite/builder.js.map +1 -0
- package/dist/vite/config.d.ts +28 -0
- package/dist/vite/config.js +1 -0
- package/dist/vite/config.js.map +1 -0
- package/dist/vite/plugins.d.ts +2 -0
- package/dist/vite/plugins.js +1 -0
- package/dist/vite/plugins.js.map +1 -0
- package/dist/vite/runners/worker.d.ts +4 -0
- package/dist/vite/runners/worker.js +1 -0
- package/dist/vite/runners/worker.js.map +1 -0
- package/dist/vite/server.d.ts +3 -0
- package/dist/vite/server.js +6 -1
- package/dist/vite/server.js.map +1 -0
- package/dist/vite/servers/main.d.ts +8 -0
- package/dist/vite/servers/main.js +1 -0
- package/dist/vite/servers/main.js.map +1 -0
- package/dist/vite/servers/worker.d.ts +11 -0
- package/dist/vite/servers/worker.js +28 -0
- package/dist/vite/servers/worker.js.map +1 -0
- package/package.json +31 -18
- package/src/cli.ts +144 -0
- package/src/config.ts +64 -0
- package/src/entrypoints/cli.ts +13 -0
- package/src/entrypoints/main.ts +200 -0
- package/src/entrypoints/thread.ts +184 -0
- package/src/entrypoints/worker.ts +48 -0
- package/src/index.ts +82 -0
- package/src/resolver.ts +16 -0
- package/src/runtime/application/api/api.ts +265 -0
- package/src/runtime/application/api/constants.ts +22 -0
- package/src/runtime/application/api/filters.ts +39 -0
- package/src/runtime/application/api/guards.ts +29 -0
- package/src/runtime/application/api/index.ts +8 -0
- package/src/runtime/application/api/middlewares.ts +37 -0
- package/src/runtime/application/api/procedure.ts +229 -0
- package/src/runtime/application/api/router.ts +193 -0
- package/src/runtime/application/api/types.ts +124 -0
- package/src/runtime/application/config.ts +69 -0
- package/src/runtime/application/constants.ts +4 -0
- package/src/runtime/application/hook.ts +51 -0
- package/src/runtime/application/hooks.ts +3 -0
- package/src/runtime/application/index.ts +5 -0
- package/src/runtime/constants.ts +13 -0
- package/src/runtime/core/hooks.ts +5 -0
- package/src/runtime/core/plugin.ts +13 -0
- package/src/runtime/core/runtime.ts +109 -0
- package/src/runtime/enums.ts +24 -0
- package/src/runtime/index.ts +21 -0
- package/src/runtime/injectables.ts +61 -0
- package/src/runtime/jobs/job.ts +370 -0
- package/src/runtime/jobs/manager.ts +332 -0
- package/src/runtime/jobs/router.ts +835 -0
- package/src/runtime/jobs/runner.ts +320 -0
- package/src/runtime/jobs/step.ts +65 -0
- package/src/runtime/jobs/ui.ts +21 -0
- package/src/runtime/pubsub/manager.ts +211 -0
- package/src/runtime/pubsub/redis.ts +108 -0
- package/src/runtime/scheduler/index.ts +39 -0
- package/src/runtime/server/applications.ts +210 -0
- package/src/runtime/server/config.ts +158 -0
- package/src/runtime/server/jobs.ts +250 -0
- package/src/runtime/server/pool.ts +260 -0
- package/src/runtime/server/proxy.ts +118 -0
- package/src/runtime/server/server.ts +155 -0
- package/src/runtime/store/index.ts +30 -0
- package/src/runtime/types.ts +93 -0
- package/src/runtime/workers/application.ts +209 -0
- package/src/runtime/workers/base.ts +68 -0
- package/src/runtime/workers/cli.ts +0 -0
- package/src/runtime/workers/job.ts +153 -0
- package/src/typings.ts +30 -0
- package/src/vite/builder.ts +122 -0
- package/src/vite/config.ts +45 -0
- package/src/vite/plugins.ts +26 -0
- package/src/vite/runners/worker.ts +57 -0
- package/src/vite/server.ts +39 -0
- package/src/vite/servers/main.ts +34 -0
- package/src/vite/servers/worker.ts +143 -0
- package/dist/_exports/application.js +0 -1
- package/dist/_exports/common.js +0 -1
- package/dist/_exports/contract.js +0 -2
- package/dist/_exports/core.js +0 -1
- package/dist/_exports/gateway.js +0 -1
- package/dist/_exports/http-transport/bun.js +0 -1
- package/dist/_exports/http-transport/deno.js +0 -1
- package/dist/_exports/http-transport/node.js +0 -1
- package/dist/_exports/http-transport.js +0 -1
- package/dist/_exports/json-format.js +0 -1
- package/dist/_exports/protocol/client.js +0 -1
- package/dist/_exports/protocol/server.js +0 -1
- package/dist/_exports/protocol.js +0 -1
- package/dist/_exports/runtime/types.js +0 -1
- package/dist/_exports/runtime.js +0 -1
- package/dist/_exports/type.js +0 -2
- package/dist/_exports/ws-transport/bun.js +0 -1
- package/dist/_exports/ws-transport/deno.js +0 -1
- package/dist/_exports/ws-transport/node.js +0 -1
- package/dist/_exports/ws-transport.js +0 -1
- package/dist/command.js +0 -30
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Container, Logger, LoggingOptions } from '@nmtjs/core';
|
|
2
|
+
import type { Job } from 'bullmq';
|
|
3
|
+
import type { LifecycleHooks } from '../core/hooks.ts';
|
|
4
|
+
import type { AnyJob } from './job.ts';
|
|
5
|
+
import type { AnyJobStep } from './step.ts';
|
|
6
|
+
export type JobRunnerOptions = {
|
|
7
|
+
logging?: LoggingOptions;
|
|
8
|
+
};
|
|
9
|
+
export interface StepResultEntry {
|
|
10
|
+
data: Record<string, unknown> | null;
|
|
11
|
+
duration: number;
|
|
12
|
+
}
|
|
13
|
+
export interface JobRunnerRunOptions {
|
|
14
|
+
signal: AbortSignal;
|
|
15
|
+
result: Record<string, unknown>;
|
|
16
|
+
stepResults: StepResultEntry[];
|
|
17
|
+
currentStepIndex: number;
|
|
18
|
+
progress: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
export interface JobRunnerRunBeforeStepParams<Options extends JobRunnerRunOptions> {
|
|
21
|
+
job: AnyJob;
|
|
22
|
+
step: AnyJobStep;
|
|
23
|
+
stepIndex: number;
|
|
24
|
+
result: Record<string, unknown>;
|
|
25
|
+
stepResults: StepResultEntry[];
|
|
26
|
+
options: Options;
|
|
27
|
+
}
|
|
28
|
+
export interface JobRunnerRunAfterStepParams<Options extends JobRunnerRunOptions> extends JobRunnerRunBeforeStepParams<Options> {
|
|
29
|
+
stepResult: StepResultEntry;
|
|
30
|
+
}
|
|
31
|
+
export declare class JobRunner<RunOptions extends JobRunnerRunOptions = JobRunnerRunOptions> {
|
|
32
|
+
protected runtime: {
|
|
33
|
+
logger: Logger;
|
|
34
|
+
container: Container;
|
|
35
|
+
lifecycleHooks: LifecycleHooks;
|
|
36
|
+
};
|
|
37
|
+
logger: Logger;
|
|
38
|
+
constructor(runtime: {
|
|
39
|
+
logger: Logger;
|
|
40
|
+
container: Container;
|
|
41
|
+
lifecycleHooks: LifecycleHooks;
|
|
42
|
+
});
|
|
43
|
+
get container(): Container;
|
|
44
|
+
runJob<T extends AnyJob>(job: T, data: any, options?: Partial<RunOptions>): Promise<T['_']['output']>;
|
|
45
|
+
protected beforeStep(params: JobRunnerRunBeforeStepParams<RunOptions>): Promise<void>;
|
|
46
|
+
protected afterStep(params: JobRunnerRunAfterStepParams<RunOptions>): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export declare class ApplicationWorkerJobRunner extends JobRunner<JobRunnerRunOptions & {
|
|
49
|
+
queueJob: Job;
|
|
50
|
+
}> {
|
|
51
|
+
protected runtime: {
|
|
52
|
+
logger: Logger;
|
|
53
|
+
container: Container;
|
|
54
|
+
lifecycleHooks: LifecycleHooks;
|
|
55
|
+
};
|
|
56
|
+
constructor(runtime: {
|
|
57
|
+
logger: Logger;
|
|
58
|
+
container: Container;
|
|
59
|
+
lifecycleHooks: LifecycleHooks;
|
|
60
|
+
});
|
|
61
|
+
protected afterStep(params: JobRunnerRunAfterStepParams<JobRunnerRunOptions & {
|
|
62
|
+
queueJob: Job;
|
|
63
|
+
}>): Promise<void>;
|
|
64
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
53
|
+
import { anyAbortSignal } from '@nmtjs/common';
|
|
54
|
+
import { Scope } from '@nmtjs/core';
|
|
55
|
+
import { UnrecoverableError } from 'bullmq';
|
|
56
|
+
import { LifecycleHook } from "../enums.js";
|
|
57
|
+
import { jobAbortSignal } from "../injectables.js";
|
|
58
|
+
export class JobRunner {
|
|
59
|
+
runtime;
|
|
60
|
+
logger;
|
|
61
|
+
constructor(runtime) {
|
|
62
|
+
this.runtime = runtime;
|
|
63
|
+
this.logger = runtime.logger.child({ $group: JobRunner.name });
|
|
64
|
+
}
|
|
65
|
+
get container() {
|
|
66
|
+
return this.runtime.container;
|
|
67
|
+
}
|
|
68
|
+
async runJob(job, data, options = {}) {
|
|
69
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
70
|
+
try {
|
|
71
|
+
const { signal: runSignal, result: runResult = {}, stepResults: runStepResults = [], progress: runProgress = {}, currentStepIndex = 0, ...rest } = options;
|
|
72
|
+
const { input, output, steps } = job;
|
|
73
|
+
const result = { ...runResult };
|
|
74
|
+
const decodedInput = input.decode(data);
|
|
75
|
+
// Initialize progress: decode from checkpoint or start fresh
|
|
76
|
+
const progress = job.progress
|
|
77
|
+
? job.progress.decode(runProgress)
|
|
78
|
+
: { ...runProgress };
|
|
79
|
+
const stopListener = __addDisposableResource(env_1, this.runtime.lifecycleHooks.once(LifecycleHook.BeforeDispose), false);
|
|
80
|
+
const signal = anyAbortSignal(runSignal, stopListener.signal);
|
|
81
|
+
const container = __addDisposableResource(env_1, this.container.fork(Scope.Global), true);
|
|
82
|
+
await container.provide(jobAbortSignal, signal);
|
|
83
|
+
const jobDependencyContext = await container.createContext(job.dependencies);
|
|
84
|
+
const jobData = job.options.data
|
|
85
|
+
? await job.options.data(jobDependencyContext, decodedInput, progress)
|
|
86
|
+
: undefined;
|
|
87
|
+
const stepResults = Array.from({ length: steps.length });
|
|
88
|
+
// Restore previous step results and reconstruct accumulated result
|
|
89
|
+
for (let stepIndex = 0; stepIndex < runStepResults.length; stepIndex++) {
|
|
90
|
+
const entry = runStepResults[stepIndex];
|
|
91
|
+
stepResults[stepIndex] = entry;
|
|
92
|
+
if (entry?.data)
|
|
93
|
+
Object.assign(result, entry.data);
|
|
94
|
+
}
|
|
95
|
+
// @ts-expect-error
|
|
96
|
+
const runOptions = {
|
|
97
|
+
signal,
|
|
98
|
+
result,
|
|
99
|
+
stepResults,
|
|
100
|
+
currentStepIndex: currentStepIndex,
|
|
101
|
+
progress,
|
|
102
|
+
...rest,
|
|
103
|
+
};
|
|
104
|
+
for (let stepIndex = currentStepIndex; stepIndex < steps.length; stepIndex++) {
|
|
105
|
+
const step = steps[stepIndex];
|
|
106
|
+
const resultSnapshot = Object.freeze(Object.assign({}, decodedInput, result));
|
|
107
|
+
try {
|
|
108
|
+
if (signal.aborted) {
|
|
109
|
+
const { reason } = signal;
|
|
110
|
+
if (reason instanceof UnrecoverableError)
|
|
111
|
+
throw reason;
|
|
112
|
+
throw new UnrecoverableError('Job cancelled');
|
|
113
|
+
}
|
|
114
|
+
const condition = job.conditions.get(stepIndex);
|
|
115
|
+
if (condition) {
|
|
116
|
+
const shouldRun = await condition({
|
|
117
|
+
context: jobDependencyContext,
|
|
118
|
+
data: jobData,
|
|
119
|
+
input: decodedInput,
|
|
120
|
+
result: resultSnapshot,
|
|
121
|
+
progress,
|
|
122
|
+
});
|
|
123
|
+
if (!shouldRun) {
|
|
124
|
+
stepResults[stepIndex] = { data: null, duration: 0 };
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const stepStartTime = Date.now();
|
|
129
|
+
await this.beforeStep({
|
|
130
|
+
job,
|
|
131
|
+
step,
|
|
132
|
+
stepIndex,
|
|
133
|
+
result,
|
|
134
|
+
options: runOptions,
|
|
135
|
+
stepResults,
|
|
136
|
+
});
|
|
137
|
+
const stepContext = await container.createContext(step.dependencies);
|
|
138
|
+
const stepInput = step.input.decode(resultSnapshot);
|
|
139
|
+
await job.beforeEachHandler?.({
|
|
140
|
+
context: jobDependencyContext,
|
|
141
|
+
data: jobData,
|
|
142
|
+
input: decodedInput,
|
|
143
|
+
result: resultSnapshot,
|
|
144
|
+
progress,
|
|
145
|
+
step,
|
|
146
|
+
stepIndex,
|
|
147
|
+
});
|
|
148
|
+
const handlerReturn = await step.handler(stepContext, stepInput, jobData);
|
|
149
|
+
const produced = step.output.encode(handlerReturn ?? {});
|
|
150
|
+
const duration = Date.now() - stepStartTime;
|
|
151
|
+
stepResults[stepIndex] = { data: produced, duration };
|
|
152
|
+
Object.assign(result, produced);
|
|
153
|
+
await job.afterEachHandler?.({
|
|
154
|
+
context: jobDependencyContext,
|
|
155
|
+
data: jobData,
|
|
156
|
+
input: decodedInput,
|
|
157
|
+
result,
|
|
158
|
+
progress,
|
|
159
|
+
step,
|
|
160
|
+
stepIndex,
|
|
161
|
+
});
|
|
162
|
+
await this.afterStep({
|
|
163
|
+
job,
|
|
164
|
+
step,
|
|
165
|
+
stepIndex,
|
|
166
|
+
result,
|
|
167
|
+
stepResult: stepResults[stepIndex],
|
|
168
|
+
stepResults,
|
|
169
|
+
options: runOptions,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
const wrapped = new Error(`Error during step [${stepIndex}]`, {
|
|
174
|
+
cause: error,
|
|
175
|
+
});
|
|
176
|
+
this.logger.error(wrapped);
|
|
177
|
+
const allowRetry = await job.onErrorHandler?.({
|
|
178
|
+
context: jobDependencyContext,
|
|
179
|
+
data: jobData,
|
|
180
|
+
input: decodedInput,
|
|
181
|
+
result: result,
|
|
182
|
+
progress,
|
|
183
|
+
step,
|
|
184
|
+
stepIndex,
|
|
185
|
+
error,
|
|
186
|
+
});
|
|
187
|
+
if (allowRetry === false) {
|
|
188
|
+
throw new UnrecoverableError('Job failed (unrecoverable)');
|
|
189
|
+
}
|
|
190
|
+
throw wrapped;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const finalPayload = await job.returnHandler({
|
|
194
|
+
context: jobDependencyContext,
|
|
195
|
+
data: jobData,
|
|
196
|
+
input: decodedInput,
|
|
197
|
+
result,
|
|
198
|
+
progress,
|
|
199
|
+
});
|
|
200
|
+
return output.encode(finalPayload);
|
|
201
|
+
}
|
|
202
|
+
catch (e_1) {
|
|
203
|
+
env_1.error = e_1;
|
|
204
|
+
env_1.hasError = true;
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
const result_1 = __disposeResources(env_1);
|
|
208
|
+
if (result_1)
|
|
209
|
+
await result_1;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async beforeStep(params) {
|
|
213
|
+
this.logger.debug({
|
|
214
|
+
job: params.job.name,
|
|
215
|
+
step: params.step.label || params.stepIndex + 1,
|
|
216
|
+
stepIndex: params.stepIndex,
|
|
217
|
+
}, 'Executing job step');
|
|
218
|
+
}
|
|
219
|
+
async afterStep(params) {
|
|
220
|
+
this.logger.debug({
|
|
221
|
+
job: params.job.name,
|
|
222
|
+
step: params.step.label || params.stepIndex + 1,
|
|
223
|
+
stepIndex: params.stepIndex,
|
|
224
|
+
}, 'Completed job step');
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
export class ApplicationWorkerJobRunner extends JobRunner {
|
|
228
|
+
runtime;
|
|
229
|
+
constructor(runtime) {
|
|
230
|
+
super(runtime);
|
|
231
|
+
this.runtime = runtime;
|
|
232
|
+
}
|
|
233
|
+
async afterStep(params) {
|
|
234
|
+
await super.afterStep(params);
|
|
235
|
+
const { job, step, result, stepResult, stepResults, stepIndex, options: { queueJob, progress }, } = params;
|
|
236
|
+
const nextStepIndex = stepIndex + 1;
|
|
237
|
+
const totalSteps = job.steps.length;
|
|
238
|
+
const percentage = Math.round((nextStepIndex / totalSteps) * 100);
|
|
239
|
+
// Encode progress before persisting if schema is defined
|
|
240
|
+
const encodedProgress = job.progress
|
|
241
|
+
? job.progress.encode(progress)
|
|
242
|
+
: progress;
|
|
243
|
+
await Promise.all([
|
|
244
|
+
queueJob.log(`Step ${step.label || nextStepIndex} completed in ${(stepResult.duration / 1000).toFixed(3)}s`),
|
|
245
|
+
queueJob.updateProgress({
|
|
246
|
+
stepIndex: nextStepIndex,
|
|
247
|
+
stepLabel: step.label,
|
|
248
|
+
result,
|
|
249
|
+
stepResults,
|
|
250
|
+
progress: encodedProgress,
|
|
251
|
+
percentage,
|
|
252
|
+
}),
|
|
253
|
+
]);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../src/runtime/jobs/runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,EAAE,cAAc,EAAE,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ybePromise } from '@nmtjs/common';
|
|
2
|
+
import type { Dependant, Dependencies, DependencyContext } from '@nmtjs/core';
|
|
3
|
+
import type { AnyObjectLikeType, ObjectType } from '@nmtjs/type/object';
|
|
4
|
+
import { t } from '@nmtjs/type';
|
|
5
|
+
import { kJobStepKey } from '../constants.ts';
|
|
6
|
+
export type AnyJobStep = JobStep<any, any, any, any, any>;
|
|
7
|
+
export type JobStepHandler<Deps extends Dependencies, Input extends AnyObjectLikeType, Output extends AnyObjectLikeType, Return, Data = any> = (context: DependencyContext<Deps>, input: t.infer.decode.output<Input>, data: Data) => MaybePromise<null extends Return ? t.infer.encode.input<Output> : Return>;
|
|
8
|
+
export interface JobStep<Input extends AnyObjectLikeType = AnyObjectLikeType, Output extends AnyObjectLikeType = AnyObjectLikeType, Deps extends Dependencies = Dependencies, Return = unknown, Data = any> extends Dependant {
|
|
9
|
+
[kJobStepKey]: any;
|
|
10
|
+
input: Input;
|
|
11
|
+
output: Output;
|
|
12
|
+
dependencies: Deps;
|
|
13
|
+
handler: JobStepHandler<Deps, Input, Output, Return, Data>;
|
|
14
|
+
}
|
|
15
|
+
export declare function createStep<Input extends AnyObjectLikeType, Output extends AnyObjectLikeType = ObjectType<{}>, Deps extends Dependencies = {}, Return = unknown, Data = any>(step: {
|
|
16
|
+
label?: string;
|
|
17
|
+
input: Input;
|
|
18
|
+
output?: Output;
|
|
19
|
+
dependencies?: Deps;
|
|
20
|
+
handler: JobStepHandler<Deps, Input, Output, Return, Data>;
|
|
21
|
+
}): JobStep<Input, Output, Deps, Return, Data>;
|
|
22
|
+
export declare function isJobStep(value: unknown): value is AnyJobStep;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { tryCaptureStackTrace } from '@nmtjs/common';
|
|
2
|
+
import { t } from '@nmtjs/type';
|
|
3
|
+
import { kJobStepKey } from "../constants.js";
|
|
4
|
+
export function createStep(step) {
|
|
5
|
+
return Object.freeze({
|
|
6
|
+
[kJobStepKey]: true,
|
|
7
|
+
output: t.object({}),
|
|
8
|
+
dependencies: {},
|
|
9
|
+
stack: tryCaptureStackTrace(),
|
|
10
|
+
...step,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export function isJobStep(value) {
|
|
14
|
+
return (typeof value === 'object' &&
|
|
15
|
+
value !== null &&
|
|
16
|
+
value[kJobStepKey] === true);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step.js","sourceRoot":"","sources":["../../../src/runtime/jobs/step.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AACpD,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAA;AAE/B,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AA8B7C,MAAM,UAAU,UAAU,CAMxB,IAMD;IACC,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,CAAC,WAAW,CAAC,EAAE,IAAI;QACnB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAsB;QACzC,YAAY,EAAE,EAAU;QACxB,KAAK,EAAE,oBAAoB,EAAE;QAC7B,GAAG,IAAI;KACR,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACb,KAAoB,CAAC,WAAW,CAAC,KAAK,IAAI,CAC5C,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
import { createBullBoard } from '@bull-board/api';
|
|
3
|
+
import { BullMQAdapter } from '@bull-board/api/bullMQAdapter';
|
|
4
|
+
import { H3Adapter } from '@bull-board/h3';
|
|
5
|
+
import { createApp, toNodeListener } from 'h3';
|
|
6
|
+
export function createJobsUI(queues) {
|
|
7
|
+
const app = createApp();
|
|
8
|
+
const serverAdapter = new H3Adapter();
|
|
9
|
+
createBullBoard({
|
|
10
|
+
queues: queues.map((q) => new BullMQAdapter(q, { readOnlyMode: true })),
|
|
11
|
+
serverAdapter,
|
|
12
|
+
});
|
|
13
|
+
const router = serverAdapter.registerHandlers();
|
|
14
|
+
app.use(router);
|
|
15
|
+
return createServer(toNodeListener(app));
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=ui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.js","sourceRoot":"","sources":["../../../src/runtime/jobs/ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAGxC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,IAAI,CAAA;AAE9C,MAAM,UAAU,YAAY,CAAC,MAAe;IAC1C,MAAM,GAAG,GAAG,SAAS,EAAE,CAAA;IACvB,MAAM,aAAa,GAAG,IAAI,SAAS,EAAE,CAAA;IACrC,eAAe,CAAC;QACd,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,aAAa,CAAC,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;QACvE,aAAa;KACd,CAAC,CAAA;IACF,MAAM,MAAM,GAAG,aAAa,CAAC,gBAAgB,EAAE,CAAA;IAC/C,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACf,OAAO,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAA;AAC1C,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import type { TAnyEventContract, TAnySubscriptionContract } from '@nmtjs/contract';
|
|
3
|
+
import type { Container, Logger } from '@nmtjs/core';
|
|
4
|
+
import type { t } from '@nmtjs/type';
|
|
5
|
+
export type PubSubAdapterEvent = {
|
|
6
|
+
channel: string;
|
|
7
|
+
payload: any;
|
|
8
|
+
};
|
|
9
|
+
export interface PubSubAdapterType {
|
|
10
|
+
publish(channel: string, payload: any): Promise<boolean>;
|
|
11
|
+
subscribe(channel: string, signal?: AbortSignal): AsyncGenerator<PubSubAdapterEvent>;
|
|
12
|
+
initialize(): Promise<void>;
|
|
13
|
+
dispose(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export type PubSubChannel = {
|
|
16
|
+
stream: Readable;
|
|
17
|
+
subscription: TAnySubscriptionContract;
|
|
18
|
+
event: TAnyEventContract;
|
|
19
|
+
};
|
|
20
|
+
export type PubSubSubscribe = <Contract extends TAnySubscriptionContract, Events extends {
|
|
21
|
+
[K in keyof Contract['events']]?: true;
|
|
22
|
+
}>(subscription: Contract, events: Events, options: Contract['options'], signal?: AbortSignal) => Omit<Readable, typeof Symbol.asyncIterator> & {
|
|
23
|
+
[Symbol.asyncIterator]: () => AsyncIterator<{} extends Events ? {
|
|
24
|
+
[K in keyof Contract['events']]: {
|
|
25
|
+
event: K;
|
|
26
|
+
data: t.infer.decode.output<Contract['events'][K]['payload']>;
|
|
27
|
+
};
|
|
28
|
+
}[keyof Contract['events']] : {
|
|
29
|
+
[K in keyof Events]: K extends keyof Contract['events'] ? {
|
|
30
|
+
event: K;
|
|
31
|
+
data: t.infer.decode.output<Contract['events'][K]['payload']>;
|
|
32
|
+
} : never;
|
|
33
|
+
}[keyof Events]>;
|
|
34
|
+
};
|
|
35
|
+
export type PubSubPublish = <S extends TAnySubscriptionContract, E extends S['events'][keyof S['events']]>(event: E, options: S['options'], data: t.infer.decode.input<E['payload']>) => Promise<boolean>;
|
|
36
|
+
export type PubSubManagerOptions = {
|
|
37
|
+
logger: Logger;
|
|
38
|
+
container: Container;
|
|
39
|
+
};
|
|
40
|
+
export declare class PubSubManager {
|
|
41
|
+
protected readonly options: PubSubManagerOptions;
|
|
42
|
+
readonly subscriptions: Map<string, PubSubChannel>;
|
|
43
|
+
constructor(options: PubSubManagerOptions);
|
|
44
|
+
protected get adapter(): PubSubAdapterType;
|
|
45
|
+
subscribe: PubSubSubscribe;
|
|
46
|
+
publish: PubSubPublish;
|
|
47
|
+
private createEventStream;
|
|
48
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { PassThrough, Readable } from 'node:stream';
|
|
4
|
+
import { isAbortError } from '@nmtjs/common';
|
|
5
|
+
import { pubSubAdapter } from "../injectables.js";
|
|
6
|
+
export class PubSubManager {
|
|
7
|
+
options;
|
|
8
|
+
subscriptions = new Map();
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
get adapter() {
|
|
13
|
+
return this.options.container.get(pubSubAdapter);
|
|
14
|
+
}
|
|
15
|
+
subscribe = (subscription, events, options, signal) => {
|
|
16
|
+
assert(this.adapter, 'PubSub adapter is not configured');
|
|
17
|
+
const eventKeys = Object.keys(events).length === 0
|
|
18
|
+
? Object.keys(subscription.events)
|
|
19
|
+
: Object.keys(events);
|
|
20
|
+
const streams = Array(eventKeys.length);
|
|
21
|
+
for (const index in eventKeys) {
|
|
22
|
+
const event = subscription.events[eventKeys[index]];
|
|
23
|
+
const channel = getChannelName(event, options);
|
|
24
|
+
if (this.subscriptions.has(channel)) {
|
|
25
|
+
streams[index] = this.subscriptions.get(channel).stream;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const iterable = this.adapter.subscribe(channel, signal);
|
|
29
|
+
const stream = this.createEventStream(iterable);
|
|
30
|
+
stream.on('close', () => this.subscriptions.delete(channel));
|
|
31
|
+
streams[index] = stream;
|
|
32
|
+
this.subscriptions.set(channel, { subscription, event, stream });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return mergeEventStreams(streams, signal);
|
|
36
|
+
};
|
|
37
|
+
publish = async (event, options, data) => {
|
|
38
|
+
assert(this.adapter, 'PubSub adapter is not configured');
|
|
39
|
+
const channel = getChannelName(event, options);
|
|
40
|
+
try {
|
|
41
|
+
const payload = event.payload.encode(data);
|
|
42
|
+
return await this.adapter.publish(channel, payload);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
this.options.logger.error(`Failed to publish event "${event.name}" on channel "${channel}": ${error.message}`);
|
|
46
|
+
return Promise.reject(error);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
createEventStream(iterable) {
|
|
50
|
+
const { subscriptions } = this;
|
|
51
|
+
return new Readable({
|
|
52
|
+
objectMode: true,
|
|
53
|
+
read() {
|
|
54
|
+
iterable.next().then(({ value, done }) => {
|
|
55
|
+
if (done) {
|
|
56
|
+
this.push(null);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const subscription = subscriptions.get(value.channel);
|
|
60
|
+
if (subscription) {
|
|
61
|
+
const { event } = subscription;
|
|
62
|
+
try {
|
|
63
|
+
const data = event.payload.decode(value.payload);
|
|
64
|
+
this.push({ event: event.name, data });
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
this.destroy(error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}, (error) => {
|
|
72
|
+
if (isAbortError(error)) {
|
|
73
|
+
this.push(null);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
this.destroy(error);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function concat(...args) {
|
|
84
|
+
return args.filter(Boolean).join('/');
|
|
85
|
+
}
|
|
86
|
+
function getChannelName(contract, options) {
|
|
87
|
+
const key = options ? serializerOptions(options) : '';
|
|
88
|
+
assert(contract.name, 'Event contract must have a name');
|
|
89
|
+
return concat(contract.name, key);
|
|
90
|
+
}
|
|
91
|
+
function serializerOptions(options) {
|
|
92
|
+
const hash = createHash('sha1');
|
|
93
|
+
const serialized = Object.entries(options)
|
|
94
|
+
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
95
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
96
|
+
.join(';');
|
|
97
|
+
hash.update(serialized);
|
|
98
|
+
return hash.digest('base64url');
|
|
99
|
+
}
|
|
100
|
+
function mergeEventStreams(streams, signal) {
|
|
101
|
+
const destination = new PassThrough({
|
|
102
|
+
signal,
|
|
103
|
+
objectMode: true,
|
|
104
|
+
readableObjectMode: true,
|
|
105
|
+
writableObjectMode: true,
|
|
106
|
+
});
|
|
107
|
+
let ended = 0;
|
|
108
|
+
for (const source of streams) {
|
|
109
|
+
source.pipe(destination, { end: false });
|
|
110
|
+
source.once('end', () => {
|
|
111
|
+
ended++;
|
|
112
|
+
if (ended === streams.length) {
|
|
113
|
+
destination.end();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return destination;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/runtime/pubsub/manager.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AASnD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AA6DjD,MAAM,OAAO,aAAa;IAGO;IAFtB,aAAa,GAAG,IAAI,GAAG,EAAyB,CAAA;IAEzD,YAA+B,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAA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ntimePlugin } from '../core/plugin.ts';
|
|
3
|
+
import type { Store } from '../types.ts';
|
|
4
|
+
import type { PubSubAdapterEvent, PubSubAdapterType } from './manager.ts';
|
|
5
|
+
export declare class RedisPubSubAdapter implements PubSubAdapterType {
|
|
6
|
+
protected readonly client: Store;
|
|
7
|
+
protected readonly events: EventEmitter<[never]>;
|
|
8
|
+
protected readonly listeners: Map<string, number>;
|
|
9
|
+
protected subscriberClient?: Store;
|
|
10
|
+
constructor(client: Store);
|
|
11
|
+
initialize(): Promise<void>;
|
|
12
|
+
dispose(): Promise<void>;
|
|
13
|
+
publish(channel: string, payload: any): Promise<boolean>;
|
|
14
|
+
subscribe(channel: string, signal?: AbortSignal): AsyncGenerator<PubSubAdapterEvent>;
|
|
15
|
+
}
|
|
16
|
+
export declare const RedisPubSubAdapterPlugin: () => RuntimePlugin;
|