@trigger.dev/core 0.0.0-v3-trigger-dirs-20240423091017 → 0.0.0-v3-update-command-20240423125505
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/v3/index.d.mts +17014 -178
- package/dist/v3/index.d.ts +17014 -178
- package/dist/v3/index.js +1273 -48
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +1261 -50
- package/dist/v3/index.mjs.map +1 -1
- package/dist/v3/otel/index.d.mts +34 -6
- package/dist/v3/otel/index.d.ts +34 -6
- package/package.json +7 -71
- package/dist/consoleInterceptor-pKvaiAI6.d.ts +0 -6677
- package/dist/consoleInterceptor-tCKb2R0l.d.mts +0 -6677
- package/dist/manager-KhqZOMNe.d.mts +0 -1158
- package/dist/manager-KhqZOMNe.d.ts +0 -1158
- package/dist/messages-oFuHKbi4.d.mts +0 -8696
- package/dist/messages-oFuHKbi4.d.ts +0 -8696
- package/dist/tracingSDK-XMTLzw35.d.mts +0 -35
- package/dist/tracingSDK-XMTLzw35.d.ts +0 -35
- package/dist/v3/dev/index.d.mts +0 -28
- package/dist/v3/dev/index.d.ts +0 -28
- package/dist/v3/dev/index.js +0 -93
- package/dist/v3/dev/index.js.map +0 -1
- package/dist/v3/dev/index.mjs +0 -91
- package/dist/v3/dev/index.mjs.map +0 -1
- package/dist/v3/prod/index.d.mts +0 -45
- package/dist/v3/prod/index.d.ts +0 -45
- package/dist/v3/prod/index.js +0 -205
- package/dist/v3/prod/index.js.map +0 -1
- package/dist/v3/prod/index.mjs +0 -203
- package/dist/v3/prod/index.mjs.map +0 -1
- package/dist/v3/utils/structuredLogger.d.mts +0 -31
- package/dist/v3/utils/structuredLogger.d.ts +0 -31
- package/dist/v3/utils/structuredLogger.js +0 -88
- package/dist/v3/utils/structuredLogger.js.map +0 -1
- package/dist/v3/utils/structuredLogger.mjs +0 -86
- package/dist/v3/utils/structuredLogger.mjs.map +0 -1
- package/dist/v3/workers/index.d.mts +0 -49
- package/dist/v3/workers/index.d.ts +0 -49
- package/dist/v3/workers/index.js +0 -2056
- package/dist/v3/workers/index.js.map +0 -1
- package/dist/v3/workers/index.mjs +0 -2051
- package/dist/v3/workers/index.mjs.map +0 -1
- package/dist/v3/zodIpc.d.mts +0 -32
- package/dist/v3/zodIpc.d.ts +0 -32
- package/dist/v3/zodIpc.js +0 -268
- package/dist/v3/zodIpc.js.map +0 -1
- package/dist/v3/zodIpc.mjs +0 -266
- package/dist/v3/zodIpc.mjs.map +0 -1
- package/dist/v3/zodMessageHandler.d.mts +0 -69
- package/dist/v3/zodMessageHandler.d.ts +0 -69
- package/dist/v3/zodMessageHandler.js +0 -168
- package/dist/v3/zodMessageHandler.js.map +0 -1
- package/dist/v3/zodMessageHandler.mjs +0 -163
- package/dist/v3/zodMessageHandler.mjs.map +0 -1
- package/dist/v3/zodNamespace.d.mts +0 -3663
- package/dist/v3/zodNamespace.d.ts +0 -3663
- package/dist/v3/zodNamespace.js +0 -356
- package/dist/v3/zodNamespace.js.map +0 -1
- package/dist/v3/zodNamespace.mjs +0 -354
- package/dist/v3/zodNamespace.mjs.map +0 -1
- package/dist/v3/zodSocket.d.mts +0 -88
- package/dist/v3/zodSocket.d.ts +0 -88
- package/dist/v3/zodSocket.js +0 -309
- package/dist/v3/zodSocket.js.map +0 -1
- package/dist/v3/zodSocket.mjs +0 -305
- package/dist/v3/zodSocket.mjs.map +0 -1
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { TracerProvider } from '@opentelemetry/api';
|
|
2
|
-
import { InstrumentationOption } from '@opentelemetry/instrumentation';
|
|
3
|
-
import { IResource, DetectorSync, ResourceDetectionConfig, Resource, ResourceAttributes } from '@opentelemetry/resources';
|
|
4
|
-
import { LoggerProvider } from '@opentelemetry/sdk-logs';
|
|
5
|
-
|
|
6
|
-
declare class AsyncResourceDetector implements DetectorSync {
|
|
7
|
-
private _promise;
|
|
8
|
-
private _resolver?;
|
|
9
|
-
private _resolved;
|
|
10
|
-
constructor();
|
|
11
|
-
detect(_config?: ResourceDetectionConfig): Resource;
|
|
12
|
-
resolveWithAttributes(attributes: ResourceAttributes): void;
|
|
13
|
-
}
|
|
14
|
-
type TracingDiagnosticLogLevel = "none" | "error" | "warn" | "info" | "debug" | "verbose" | "all";
|
|
15
|
-
type TracingSDKConfig = {
|
|
16
|
-
url: string;
|
|
17
|
-
forceFlushTimeoutMillis?: number;
|
|
18
|
-
resource?: IResource;
|
|
19
|
-
instrumentations?: InstrumentationOption[];
|
|
20
|
-
diagLogLevel?: TracingDiagnosticLogLevel;
|
|
21
|
-
};
|
|
22
|
-
declare class TracingSDK {
|
|
23
|
-
private readonly config;
|
|
24
|
-
readonly asyncResourceDetector: AsyncResourceDetector;
|
|
25
|
-
private readonly _logProvider;
|
|
26
|
-
private readonly _spanExporter;
|
|
27
|
-
private readonly _traceProvider;
|
|
28
|
-
readonly getLogger: LoggerProvider["getLogger"];
|
|
29
|
-
readonly getTracer: TracerProvider["getTracer"];
|
|
30
|
-
constructor(config: TracingSDKConfig);
|
|
31
|
-
flush(): Promise<void>;
|
|
32
|
-
shutdown(): Promise<void>;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { TracingSDK as T, type TracingDiagnosticLogLevel as a, type TracingSDKConfig as b };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { TracerProvider } from '@opentelemetry/api';
|
|
2
|
-
import { InstrumentationOption } from '@opentelemetry/instrumentation';
|
|
3
|
-
import { IResource, DetectorSync, ResourceDetectionConfig, Resource, ResourceAttributes } from '@opentelemetry/resources';
|
|
4
|
-
import { LoggerProvider } from '@opentelemetry/sdk-logs';
|
|
5
|
-
|
|
6
|
-
declare class AsyncResourceDetector implements DetectorSync {
|
|
7
|
-
private _promise;
|
|
8
|
-
private _resolver?;
|
|
9
|
-
private _resolved;
|
|
10
|
-
constructor();
|
|
11
|
-
detect(_config?: ResourceDetectionConfig): Resource;
|
|
12
|
-
resolveWithAttributes(attributes: ResourceAttributes): void;
|
|
13
|
-
}
|
|
14
|
-
type TracingDiagnosticLogLevel = "none" | "error" | "warn" | "info" | "debug" | "verbose" | "all";
|
|
15
|
-
type TracingSDKConfig = {
|
|
16
|
-
url: string;
|
|
17
|
-
forceFlushTimeoutMillis?: number;
|
|
18
|
-
resource?: IResource;
|
|
19
|
-
instrumentations?: InstrumentationOption[];
|
|
20
|
-
diagLogLevel?: TracingDiagnosticLogLevel;
|
|
21
|
-
};
|
|
22
|
-
declare class TracingSDK {
|
|
23
|
-
private readonly config;
|
|
24
|
-
readonly asyncResourceDetector: AsyncResourceDetector;
|
|
25
|
-
private readonly _logProvider;
|
|
26
|
-
private readonly _spanExporter;
|
|
27
|
-
private readonly _traceProvider;
|
|
28
|
-
readonly getLogger: LoggerProvider["getLogger"];
|
|
29
|
-
readonly getTracer: TracerProvider["getTracer"];
|
|
30
|
-
constructor(config: TracingSDKConfig);
|
|
31
|
-
flush(): Promise<void>;
|
|
32
|
-
shutdown(): Promise<void>;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { TracingSDK as T, type TracingDiagnosticLogLevel as a, type TracingSDKConfig as b };
|
package/dist/v3/dev/index.d.mts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { R as RuntimeManager, T as TaskRunExecutionResult, B as BatchTaskRunExecutionResult, b as TaskRunContext, p as TaskRunExecution } from '../../manager-KhqZOMNe.mjs';
|
|
2
|
-
import 'zod';
|
|
3
|
-
|
|
4
|
-
declare class DevRuntimeManager implements RuntimeManager {
|
|
5
|
-
_taskWaits: Map<string, {
|
|
6
|
-
resolve: (value: TaskRunExecutionResult) => void;
|
|
7
|
-
}>;
|
|
8
|
-
_batchWaits: Map<string, {
|
|
9
|
-
resolve: (value: BatchTaskRunExecutionResult) => void;
|
|
10
|
-
reject: (err?: any) => void;
|
|
11
|
-
}>;
|
|
12
|
-
_pendingCompletionNotifications: Map<string, TaskRunExecutionResult>;
|
|
13
|
-
disable(): void;
|
|
14
|
-
waitForDuration(ms: number): Promise<void>;
|
|
15
|
-
waitUntil(date: Date): Promise<void>;
|
|
16
|
-
waitForTask(params: {
|
|
17
|
-
id: string;
|
|
18
|
-
ctx: TaskRunContext;
|
|
19
|
-
}): Promise<TaskRunExecutionResult>;
|
|
20
|
-
waitForBatch(params: {
|
|
21
|
-
id: string;
|
|
22
|
-
runs: string[];
|
|
23
|
-
ctx: TaskRunContext;
|
|
24
|
-
}): Promise<BatchTaskRunExecutionResult>;
|
|
25
|
-
resumeTask(completion: TaskRunExecutionResult, execution: TaskRunExecution): void;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { DevRuntimeManager };
|
package/dist/v3/dev/index.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { R as RuntimeManager, T as TaskRunExecutionResult, B as BatchTaskRunExecutionResult, b as TaskRunContext, p as TaskRunExecution } from '../../manager-KhqZOMNe.js';
|
|
2
|
-
import 'zod';
|
|
3
|
-
|
|
4
|
-
declare class DevRuntimeManager implements RuntimeManager {
|
|
5
|
-
_taskWaits: Map<string, {
|
|
6
|
-
resolve: (value: TaskRunExecutionResult) => void;
|
|
7
|
-
}>;
|
|
8
|
-
_batchWaits: Map<string, {
|
|
9
|
-
resolve: (value: BatchTaskRunExecutionResult) => void;
|
|
10
|
-
reject: (err?: any) => void;
|
|
11
|
-
}>;
|
|
12
|
-
_pendingCompletionNotifications: Map<string, TaskRunExecutionResult>;
|
|
13
|
-
disable(): void;
|
|
14
|
-
waitForDuration(ms: number): Promise<void>;
|
|
15
|
-
waitUntil(date: Date): Promise<void>;
|
|
16
|
-
waitForTask(params: {
|
|
17
|
-
id: string;
|
|
18
|
-
ctx: TaskRunContext;
|
|
19
|
-
}): Promise<TaskRunExecutionResult>;
|
|
20
|
-
waitForBatch(params: {
|
|
21
|
-
id: string;
|
|
22
|
-
runs: string[];
|
|
23
|
-
ctx: TaskRunContext;
|
|
24
|
-
}): Promise<BatchTaskRunExecutionResult>;
|
|
25
|
-
resumeTask(completion: TaskRunExecutionResult, execution: TaskRunExecution): void;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { DevRuntimeManager };
|
package/dist/v3/dev/index.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var promises = require('timers/promises');
|
|
4
|
-
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
-
var __publicField = (obj, key, value) => {
|
|
9
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
|
-
return value;
|
|
11
|
-
};
|
|
12
|
-
async function unboundedTimeout(delay = 0, value, options) {
|
|
13
|
-
const maxDelay = 2147483647;
|
|
14
|
-
const fullTimeouts = Math.floor(delay / maxDelay);
|
|
15
|
-
const remainingDelay = delay % maxDelay;
|
|
16
|
-
let lastTimeoutResult = await promises.setTimeout(remainingDelay, value, options);
|
|
17
|
-
for (let i = 0; i < fullTimeouts; i++) {
|
|
18
|
-
lastTimeoutResult = await promises.setTimeout(maxDelay, value, options);
|
|
19
|
-
}
|
|
20
|
-
return lastTimeoutResult;
|
|
21
|
-
}
|
|
22
|
-
__name(unboundedTimeout, "unboundedTimeout");
|
|
23
|
-
|
|
24
|
-
// src/v3/runtime/devRuntimeManager.ts
|
|
25
|
-
var _DevRuntimeManager = class _DevRuntimeManager {
|
|
26
|
-
constructor() {
|
|
27
|
-
__publicField(this, "_taskWaits", /* @__PURE__ */ new Map());
|
|
28
|
-
__publicField(this, "_batchWaits", /* @__PURE__ */ new Map());
|
|
29
|
-
__publicField(this, "_pendingCompletionNotifications", /* @__PURE__ */ new Map());
|
|
30
|
-
}
|
|
31
|
-
disable() {
|
|
32
|
-
}
|
|
33
|
-
async waitForDuration(ms) {
|
|
34
|
-
await unboundedTimeout(ms);
|
|
35
|
-
}
|
|
36
|
-
async waitUntil(date) {
|
|
37
|
-
return this.waitForDuration(date.getTime() - Date.now());
|
|
38
|
-
}
|
|
39
|
-
async waitForTask(params) {
|
|
40
|
-
const pendingCompletion = this._pendingCompletionNotifications.get(params.id);
|
|
41
|
-
if (pendingCompletion) {
|
|
42
|
-
this._pendingCompletionNotifications.delete(params.id);
|
|
43
|
-
return pendingCompletion;
|
|
44
|
-
}
|
|
45
|
-
const promise = new Promise((resolve) => {
|
|
46
|
-
this._taskWaits.set(params.id, {
|
|
47
|
-
resolve
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
return await promise;
|
|
51
|
-
}
|
|
52
|
-
async waitForBatch(params) {
|
|
53
|
-
if (!params.runs.length) {
|
|
54
|
-
return Promise.resolve({
|
|
55
|
-
id: params.id,
|
|
56
|
-
items: []
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
const promise = Promise.all(params.runs.map((runId) => {
|
|
60
|
-
return new Promise((resolve, reject) => {
|
|
61
|
-
const pendingCompletion = this._pendingCompletionNotifications.get(runId);
|
|
62
|
-
if (pendingCompletion) {
|
|
63
|
-
this._pendingCompletionNotifications.delete(runId);
|
|
64
|
-
resolve(pendingCompletion);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
this._taskWaits.set(runId, {
|
|
68
|
-
resolve
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
}));
|
|
72
|
-
const results = await promise;
|
|
73
|
-
return {
|
|
74
|
-
id: params.id,
|
|
75
|
-
items: results
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
resumeTask(completion, execution) {
|
|
79
|
-
const wait = this._taskWaits.get(execution.run.id);
|
|
80
|
-
if (!wait) {
|
|
81
|
-
this._pendingCompletionNotifications.set(execution.run.id, completion);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
wait.resolve(completion);
|
|
85
|
-
this._taskWaits.delete(execution.run.id);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
__name(_DevRuntimeManager, "DevRuntimeManager");
|
|
89
|
-
var DevRuntimeManager = _DevRuntimeManager;
|
|
90
|
-
|
|
91
|
-
exports.DevRuntimeManager = DevRuntimeManager;
|
|
92
|
-
//# sourceMappingURL=out.js.map
|
|
93
|
-
//# sourceMappingURL=index.js.map
|
package/dist/v3/dev/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/v3/utils/timers.ts","../../../src/v3/runtime/devRuntimeManager.ts"],"names":["setTimeout","unboundedTimeout","delay","value","options","maxDelay","fullTimeouts","Math","floor","remainingDelay","lastTimeoutResult","i","DevRuntimeManager","_taskWaits","Map","_batchWaits","_pendingCompletionNotifications","disable","waitForDuration","ms","waitUntil","date","getTime","Date","now","waitForTask","params","pendingCompletion","get","id","delete","promise","Promise","resolve","set","waitForBatch","runs","length","items","all","map","runId","reject","results","resumeTask","completion","execution","wait","run"],"mappings":";;;;;;;;;AACA,SAASA,kBAAkB;AAE3B,eAAsBC,iBACpBC,QAAgB,GAChBC,OACAC,SACY;AACZ,QAAMC,WAAW;AAEjB,QAAMC,eAAeC,KAAKC,MAAMN,QAAQG,QAAAA;AACxC,QAAMI,iBAAiBP,QAAQG;AAE/B,MAAIK,oBAAoB,MAAMV,WAAWS,gBAAgBN,OAAOC,OAAAA;AAEhE,WAASO,IAAI,GAAGA,IAAIL,cAAcK,KAAK;AACrCD,wBAAoB,MAAMV,WAAWK,UAAUF,OAAOC,OAAAA;EACxD;AAEA,SAAOM;AACT;AAjBsBT;;;ACMf,IAAMW,qBAAN,MAAMA,mBAAAA;EAAN;AACLC,sCAAgF,oBAAIC,IAAAA;AAEpFC,uCAGI,oBAAID,IAAAA;AAERE,2DAAuE,oBAAIF,IAAAA;;EAE3EG,UAAgB;EAEhB;EAEA,MAAMC,gBAAgBC,IAA2B;AAC/C,UAAMlB,iBAAiBkB,EAAAA;E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;AAEb,SAAKhC,WAAWiB,OAAOgB,UAAUE,IAAInB,EAAE;EACzC;AACF;AAvFajB;AAAN,IAAMA,oBAAN","sourcesContent":["import { TimerOptions } from \"node:timers\";\nimport { setTimeout } from \"node:timers/promises\";\n\nexport async function unboundedTimeout<T = void>(\n delay: number = 0,\n value?: T,\n options?: TimerOptions\n): Promise<T> {\n const maxDelay = 2147483647; // Highest value that will fit in a 32-bit signed integer\n\n const fullTimeouts = Math.floor(delay / maxDelay);\n const remainingDelay = delay % maxDelay;\n\n let lastTimeoutResult = await setTimeout(remainingDelay, value, options);\n\n for (let i = 0; i < fullTimeouts; i++) {\n lastTimeoutResult = await setTimeout(maxDelay, value, options);\n }\n\n return lastTimeoutResult;\n}\n","import {\n BatchTaskRunExecutionResult,\n TaskRunContext,\n TaskRunExecution,\n TaskRunExecutionResult,\n} from \"../schemas\";\nimport { RuntimeManager } from \"./manager\";\nimport { unboundedTimeout } from \"../utils/timers\";\n\nexport class DevRuntimeManager implements RuntimeManager {\n _taskWaits: Map<string, { resolve: (value: TaskRunExecutionResult) => void }> = new Map();\n\n _batchWaits: Map<\n string,\n { resolve: (value: BatchTaskRunExecutionResult) => void; reject: (err?: any) => void }\n > = new Map();\n\n _pendingCompletionNotifications: Map<string, TaskRunExecutionResult> = new Map();\n\n disable(): void {\n // do nothing\n }\n\n async waitForDuration(ms: number): Promise<void> {\n await unboundedTimeout(ms);\n }\n\n async waitUntil(date: Date): Promise<void> {\n return this.waitForDuration(date.getTime() - Date.now());\n }\n\n async waitForTask(params: { id: string; ctx: TaskRunContext }): Promise<TaskRunExecutionResult> {\n const pendingCompletion = this._pendingCompletionNotifications.get(params.id);\n\n if (pendingCompletion) {\n this._pendingCompletionNotifications.delete(params.id);\n\n return pendingCompletion;\n }\n\n const promise = new Promise<TaskRunExecutionResult>((resolve) => {\n this._taskWaits.set(params.id, { resolve });\n });\n\n return await promise;\n }\n\n async waitForBatch(params: {\n id: string;\n runs: string[];\n ctx: TaskRunContext;\n }): Promise<BatchTaskRunExecutionResult> {\n if (!params.runs.length) {\n return Promise.resolve({ id: params.id, items: [] });\n }\n\n const promise = Promise.all(\n params.runs.map((runId) => {\n return new Promise<TaskRunExecutionResult>((resolve, reject) => {\n const pendingCompletion = this._pendingCompletionNotifications.get(runId);\n\n if (pendingCompletion) {\n this._pendingCompletionNotifications.delete(runId);\n\n resolve(pendingCompletion);\n\n return;\n }\n\n this._taskWaits.set(runId, { resolve });\n });\n })\n );\n\n const results = await promise;\n\n return {\n id: params.id,\n items: results,\n };\n }\n\n resumeTask(completion: TaskRunExecutionResult, execution: TaskRunExecution): void {\n const wait = this._taskWaits.get(execution.run.id);\n\n if (!wait) {\n // We need to store the completion in case the task is awaited later\n this._pendingCompletionNotifications.set(execution.run.id, completion);\n\n return;\n }\n\n wait.resolve(completion);\n\n this._taskWaits.delete(execution.run.id);\n }\n}\n"]}
|
package/dist/v3/dev/index.mjs
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { setTimeout } from 'node:timers/promises';
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __publicField = (obj, key, value) => {
|
|
7
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
-
return value;
|
|
9
|
-
};
|
|
10
|
-
async function unboundedTimeout(delay = 0, value, options) {
|
|
11
|
-
const maxDelay = 2147483647;
|
|
12
|
-
const fullTimeouts = Math.floor(delay / maxDelay);
|
|
13
|
-
const remainingDelay = delay % maxDelay;
|
|
14
|
-
let lastTimeoutResult = await setTimeout(remainingDelay, value, options);
|
|
15
|
-
for (let i = 0; i < fullTimeouts; i++) {
|
|
16
|
-
lastTimeoutResult = await setTimeout(maxDelay, value, options);
|
|
17
|
-
}
|
|
18
|
-
return lastTimeoutResult;
|
|
19
|
-
}
|
|
20
|
-
__name(unboundedTimeout, "unboundedTimeout");
|
|
21
|
-
|
|
22
|
-
// src/v3/runtime/devRuntimeManager.ts
|
|
23
|
-
var _DevRuntimeManager = class _DevRuntimeManager {
|
|
24
|
-
constructor() {
|
|
25
|
-
__publicField(this, "_taskWaits", /* @__PURE__ */ new Map());
|
|
26
|
-
__publicField(this, "_batchWaits", /* @__PURE__ */ new Map());
|
|
27
|
-
__publicField(this, "_pendingCompletionNotifications", /* @__PURE__ */ new Map());
|
|
28
|
-
}
|
|
29
|
-
disable() {
|
|
30
|
-
}
|
|
31
|
-
async waitForDuration(ms) {
|
|
32
|
-
await unboundedTimeout(ms);
|
|
33
|
-
}
|
|
34
|
-
async waitUntil(date) {
|
|
35
|
-
return this.waitForDuration(date.getTime() - Date.now());
|
|
36
|
-
}
|
|
37
|
-
async waitForTask(params) {
|
|
38
|
-
const pendingCompletion = this._pendingCompletionNotifications.get(params.id);
|
|
39
|
-
if (pendingCompletion) {
|
|
40
|
-
this._pendingCompletionNotifications.delete(params.id);
|
|
41
|
-
return pendingCompletion;
|
|
42
|
-
}
|
|
43
|
-
const promise = new Promise((resolve) => {
|
|
44
|
-
this._taskWaits.set(params.id, {
|
|
45
|
-
resolve
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
return await promise;
|
|
49
|
-
}
|
|
50
|
-
async waitForBatch(params) {
|
|
51
|
-
if (!params.runs.length) {
|
|
52
|
-
return Promise.resolve({
|
|
53
|
-
id: params.id,
|
|
54
|
-
items: []
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
const promise = Promise.all(params.runs.map((runId) => {
|
|
58
|
-
return new Promise((resolve, reject) => {
|
|
59
|
-
const pendingCompletion = this._pendingCompletionNotifications.get(runId);
|
|
60
|
-
if (pendingCompletion) {
|
|
61
|
-
this._pendingCompletionNotifications.delete(runId);
|
|
62
|
-
resolve(pendingCompletion);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
this._taskWaits.set(runId, {
|
|
66
|
-
resolve
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
}));
|
|
70
|
-
const results = await promise;
|
|
71
|
-
return {
|
|
72
|
-
id: params.id,
|
|
73
|
-
items: results
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
resumeTask(completion, execution) {
|
|
77
|
-
const wait = this._taskWaits.get(execution.run.id);
|
|
78
|
-
if (!wait) {
|
|
79
|
-
this._pendingCompletionNotifications.set(execution.run.id, completion);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
wait.resolve(completion);
|
|
83
|
-
this._taskWaits.delete(execution.run.id);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
__name(_DevRuntimeManager, "DevRuntimeManager");
|
|
87
|
-
var DevRuntimeManager = _DevRuntimeManager;
|
|
88
|
-
|
|
89
|
-
export { DevRuntimeManager };
|
|
90
|
-
//# sourceMappingURL=out.js.map
|
|
91
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/v3/utils/timers.ts","../../../src/v3/runtime/devRuntimeManager.ts"],"names":["setTimeout","unboundedTimeout","delay","value","options","maxDelay","fullTimeouts","Math","floor","remainingDelay","lastTimeoutResult","i","DevRuntimeManager","_taskWaits","Map","_batchWaits","_pendingCompletionNotifications","disable","waitForDuration","ms","waitUntil","date","getTime","Date","now","waitForTask","params","pendingCompletion","get","id","delete","promise","Promise","resolve","set","waitForBatch","runs","length","items","all","map","runId","reject","results","resumeTask","completion","execution","wait","run"],"mappings":";;;;;;;;;AACA,SAASA,kBAAkB;AAE3B,eAAsBC,iBACpBC,QAAgB,GAChBC,OACAC,SACY;AACZ,QAAMC,WAAW;AAEjB,QAAMC,eAAeC,KAAKC,MAAMN,QAAQG,QAAAA;AACxC,QAAMI,iBAAiBP,QAAQG;AAE/B,MAAIK,oBAAoB,MAAMV,WAAWS,g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Kd,WAAWqB,IAAIO,OAAO;UAAER;QAAQ,CAAA;MACvC,CAAA;IACF,CAAA,CAAA;AAGF,UAAMU,UAAU,MAAMZ;AAEtB,WAAO;MACLF,IAAIH,OAAOG;MACXS,OAAOK;IACT;EACF;EAEAC,WAAWC,YAAoCC,WAAmC;AAChF,UAAMC,OAAO,KAAKlC,WAAWe,IAAIkB,UAAUE,IAAInB,EAAE;AAEjD,QAAI,CAACkB,MAAM;AAET,WAAK/B,gCAAgCkB,IAAIY,UAAUE,IAAInB,IAAIgB,UAAAA;AAE3D;IACF;AAEAE,SAAKd,QAAQY,UAAAA;AAEb,SAAKhC,WAAWiB,OAAOgB,UAAUE,IAAInB,EAAE;EACzC;AACF;AAvFajB;AAAN,IAAMA,oBAAN","sourcesContent":["import { TimerOptions } from \"node:timers\";\nimport { setTimeout } from \"node:timers/promises\";\n\nexport async function unboundedTimeout<T = void>(\n delay: number = 0,\n value?: T,\n options?: TimerOptions\n): Promise<T> {\n const maxDelay = 2147483647; // Highest value that will fit in a 32-bit signed integer\n\n const fullTimeouts = Math.floor(delay / maxDelay);\n const remainingDelay = delay % maxDelay;\n\n let lastTimeoutResult = await setTimeout(remainingDelay, value, options);\n\n for (let i = 0; i < fullTimeouts; i++) {\n lastTimeoutResult = await setTimeout(maxDelay, value, options);\n }\n\n return lastTimeoutResult;\n}\n","import {\n BatchTaskRunExecutionResult,\n TaskRunContext,\n TaskRunExecution,\n TaskRunExecutionResult,\n} from \"../schemas\";\nimport { RuntimeManager } from \"./manager\";\nimport { unboundedTimeout } from \"../utils/timers\";\n\nexport class DevRuntimeManager implements RuntimeManager {\n _taskWaits: Map<string, { resolve: (value: TaskRunExecutionResult) => void }> = new Map();\n\n _batchWaits: Map<\n string,\n { resolve: (value: BatchTaskRunExecutionResult) => void; reject: (err?: any) => void }\n > = new Map();\n\n _pendingCompletionNotifications: Map<string, TaskRunExecutionResult> = new Map();\n\n disable(): void {\n // do nothing\n }\n\n async waitForDuration(ms: number): Promise<void> {\n await unboundedTimeout(ms);\n }\n\n async waitUntil(date: Date): Promise<void> {\n return this.waitForDuration(date.getTime() - Date.now());\n }\n\n async waitForTask(params: { id: string; ctx: TaskRunContext }): Promise<TaskRunExecutionResult> {\n const pendingCompletion = this._pendingCompletionNotifications.get(params.id);\n\n if (pendingCompletion) {\n this._pendingCompletionNotifications.delete(params.id);\n\n return pendingCompletion;\n }\n\n const promise = new Promise<TaskRunExecutionResult>((resolve) => {\n this._taskWaits.set(params.id, { resolve });\n });\n\n return await promise;\n }\n\n async waitForBatch(params: {\n id: string;\n runs: string[];\n ctx: TaskRunContext;\n }): Promise<BatchTaskRunExecutionResult> {\n if (!params.runs.length) {\n return Promise.resolve({ id: params.id, items: [] });\n }\n\n const promise = Promise.all(\n params.runs.map((runId) => {\n return new Promise<TaskRunExecutionResult>((resolve, reject) => {\n const pendingCompletion = this._pendingCompletionNotifications.get(runId);\n\n if (pendingCompletion) {\n this._pendingCompletionNotifications.delete(runId);\n\n resolve(pendingCompletion);\n\n return;\n }\n\n this._taskWaits.set(runId, { resolve });\n });\n })\n );\n\n const results = await promise;\n\n return {\n id: params.id,\n items: results,\n };\n }\n\n resumeTask(completion: TaskRunExecutionResult, execution: TaskRunExecution): void {\n const wait = this._taskWaits.get(execution.run.id);\n\n if (!wait) {\n // We need to store the completion in case the task is awaited later\n this._pendingCompletionNotifications.set(execution.run.id, completion);\n\n return;\n }\n\n wait.resolve(completion);\n\n this._taskWaits.delete(execution.run.id);\n }\n}\n"]}
|
package/dist/v3/prod/index.d.mts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { R as RuntimeManager, T as TaskRunExecutionResult, B as BatchTaskRunExecutionResult, b as TaskRunContext, p as TaskRunExecution } from '../../manager-KhqZOMNe.mjs';
|
|
2
|
-
import { n as ProdWorkerToChildMessages, m as ProdChildToWorkerMessages } from '../../messages-oFuHKbi4.mjs';
|
|
3
|
-
import { ZodIpcConnection } from '../zodIpc.mjs';
|
|
4
|
-
import 'zod';
|
|
5
|
-
import '../zodSocket.mjs';
|
|
6
|
-
import 'socket.io-client';
|
|
7
|
-
import '../zodMessageHandler.mjs';
|
|
8
|
-
import '../utils/structuredLogger.mjs';
|
|
9
|
-
|
|
10
|
-
type ProdRuntimeManagerOptions = {
|
|
11
|
-
waitThresholdInMs?: number;
|
|
12
|
-
};
|
|
13
|
-
declare class ProdRuntimeManager implements RuntimeManager {
|
|
14
|
-
private ipc;
|
|
15
|
-
private options;
|
|
16
|
-
_taskWaits: Map<string, {
|
|
17
|
-
resolve: (value: TaskRunExecutionResult) => void;
|
|
18
|
-
}>;
|
|
19
|
-
_batchWaits: Map<string, {
|
|
20
|
-
resolve: (value: BatchTaskRunExecutionResult) => void;
|
|
21
|
-
reject: (err?: any) => void;
|
|
22
|
-
}>;
|
|
23
|
-
_waitForRestore: {
|
|
24
|
-
resolve: (value: "restore") => void;
|
|
25
|
-
reject: (err?: any) => void;
|
|
26
|
-
} | undefined;
|
|
27
|
-
constructor(ipc: ZodIpcConnection<typeof ProdWorkerToChildMessages, typeof ProdChildToWorkerMessages>, options?: ProdRuntimeManagerOptions);
|
|
28
|
-
disable(): void;
|
|
29
|
-
waitForDuration(ms: number): Promise<void>;
|
|
30
|
-
resumeAfterRestore(): void;
|
|
31
|
-
waitUntil(date: Date): Promise<void>;
|
|
32
|
-
waitForTask(params: {
|
|
33
|
-
id: string;
|
|
34
|
-
ctx: TaskRunContext;
|
|
35
|
-
}): Promise<TaskRunExecutionResult>;
|
|
36
|
-
waitForBatch(params: {
|
|
37
|
-
id: string;
|
|
38
|
-
runs: string[];
|
|
39
|
-
ctx: TaskRunContext;
|
|
40
|
-
}): Promise<BatchTaskRunExecutionResult>;
|
|
41
|
-
resumeTask(completion: TaskRunExecutionResult, execution: TaskRunExecution): void;
|
|
42
|
-
private get waitThresholdInMs();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { ProdRuntimeManager };
|
package/dist/v3/prod/index.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { R as RuntimeManager, T as TaskRunExecutionResult, B as BatchTaskRunExecutionResult, b as TaskRunContext, p as TaskRunExecution } from '../../manager-KhqZOMNe.js';
|
|
2
|
-
import { n as ProdWorkerToChildMessages, m as ProdChildToWorkerMessages } from '../../messages-oFuHKbi4.js';
|
|
3
|
-
import { ZodIpcConnection } from '../zodIpc.js';
|
|
4
|
-
import 'zod';
|
|
5
|
-
import '../zodSocket.js';
|
|
6
|
-
import 'socket.io-client';
|
|
7
|
-
import '../zodMessageHandler.js';
|
|
8
|
-
import '../utils/structuredLogger.js';
|
|
9
|
-
|
|
10
|
-
type ProdRuntimeManagerOptions = {
|
|
11
|
-
waitThresholdInMs?: number;
|
|
12
|
-
};
|
|
13
|
-
declare class ProdRuntimeManager implements RuntimeManager {
|
|
14
|
-
private ipc;
|
|
15
|
-
private options;
|
|
16
|
-
_taskWaits: Map<string, {
|
|
17
|
-
resolve: (value: TaskRunExecutionResult) => void;
|
|
18
|
-
}>;
|
|
19
|
-
_batchWaits: Map<string, {
|
|
20
|
-
resolve: (value: BatchTaskRunExecutionResult) => void;
|
|
21
|
-
reject: (err?: any) => void;
|
|
22
|
-
}>;
|
|
23
|
-
_waitForRestore: {
|
|
24
|
-
resolve: (value: "restore") => void;
|
|
25
|
-
reject: (err?: any) => void;
|
|
26
|
-
} | undefined;
|
|
27
|
-
constructor(ipc: ZodIpcConnection<typeof ProdWorkerToChildMessages, typeof ProdChildToWorkerMessages>, options?: ProdRuntimeManagerOptions);
|
|
28
|
-
disable(): void;
|
|
29
|
-
waitForDuration(ms: number): Promise<void>;
|
|
30
|
-
resumeAfterRestore(): void;
|
|
31
|
-
waitUntil(date: Date): Promise<void>;
|
|
32
|
-
waitForTask(params: {
|
|
33
|
-
id: string;
|
|
34
|
-
ctx: TaskRunContext;
|
|
35
|
-
}): Promise<TaskRunExecutionResult>;
|
|
36
|
-
waitForBatch(params: {
|
|
37
|
-
id: string;
|
|
38
|
-
runs: string[];
|
|
39
|
-
ctx: TaskRunContext;
|
|
40
|
-
}): Promise<BatchTaskRunExecutionResult>;
|
|
41
|
-
resumeTask(completion: TaskRunExecutionResult, execution: TaskRunExecution): void;
|
|
42
|
-
private get waitThresholdInMs();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { ProdRuntimeManager };
|
package/dist/v3/prod/index.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var preciseDate = require('@google-cloud/precise-date');
|
|
4
|
-
var promises = require('timers/promises');
|
|
5
|
-
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
-
var __accessCheck = (obj, member, msg) => {
|
|
9
|
-
if (!member.has(obj))
|
|
10
|
-
throw TypeError("Cannot " + msg);
|
|
11
|
-
};
|
|
12
|
-
var __privateAdd = (obj, member, value) => {
|
|
13
|
-
if (member.has(obj))
|
|
14
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
15
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
16
|
-
};
|
|
17
|
-
var __privateMethod = (obj, member, method) => {
|
|
18
|
-
__accessCheck(obj, member, "access private method");
|
|
19
|
-
return method;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// src/v3/utils/platform.ts
|
|
23
|
-
var _globalThis = typeof globalThis === "object" ? globalThis : global;
|
|
24
|
-
|
|
25
|
-
// src/v3/utils/globals.ts
|
|
26
|
-
var GLOBAL_TRIGGER_DOT_DEV_KEY = Symbol.for(`dev.trigger.ts.api`);
|
|
27
|
-
var _global = _globalThis;
|
|
28
|
-
function registerGlobal(type, instance, allowOverride = false) {
|
|
29
|
-
const api = _global[GLOBAL_TRIGGER_DOT_DEV_KEY] = _global[GLOBAL_TRIGGER_DOT_DEV_KEY] ?? {};
|
|
30
|
-
if (!allowOverride && api[type]) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
api[type] = instance;
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
__name(registerGlobal, "registerGlobal");
|
|
37
|
-
function getGlobal(type) {
|
|
38
|
-
return _global[GLOBAL_TRIGGER_DOT_DEV_KEY]?.[type];
|
|
39
|
-
}
|
|
40
|
-
__name(getGlobal, "getGlobal");
|
|
41
|
-
var _SimpleClock = class _SimpleClock {
|
|
42
|
-
preciseNow() {
|
|
43
|
-
const now = new preciseDate.PreciseDate();
|
|
44
|
-
const nowStruct = now.toStruct();
|
|
45
|
-
return [
|
|
46
|
-
nowStruct.seconds,
|
|
47
|
-
nowStruct.nanos
|
|
48
|
-
];
|
|
49
|
-
}
|
|
50
|
-
reset() {
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
__name(_SimpleClock, "SimpleClock");
|
|
54
|
-
var SimpleClock = _SimpleClock;
|
|
55
|
-
|
|
56
|
-
// src/v3/clock/index.ts
|
|
57
|
-
var API_NAME = "clock";
|
|
58
|
-
var SIMPLE_CLOCK = new SimpleClock();
|
|
59
|
-
var _getClock, getClock_fn;
|
|
60
|
-
var _ClockAPI = class _ClockAPI {
|
|
61
|
-
constructor() {
|
|
62
|
-
__privateAdd(this, _getClock);
|
|
63
|
-
}
|
|
64
|
-
static getInstance() {
|
|
65
|
-
if (!this._instance) {
|
|
66
|
-
this._instance = new _ClockAPI();
|
|
67
|
-
}
|
|
68
|
-
return this._instance;
|
|
69
|
-
}
|
|
70
|
-
setGlobalClock(clock2) {
|
|
71
|
-
return registerGlobal(API_NAME, clock2);
|
|
72
|
-
}
|
|
73
|
-
preciseNow() {
|
|
74
|
-
return __privateMethod(this, _getClock, getClock_fn).call(this).preciseNow();
|
|
75
|
-
}
|
|
76
|
-
reset() {
|
|
77
|
-
__privateMethod(this, _getClock, getClock_fn).call(this).reset();
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
_getClock = new WeakSet();
|
|
81
|
-
getClock_fn = /* @__PURE__ */ __name(function() {
|
|
82
|
-
return getGlobal(API_NAME) ?? SIMPLE_CLOCK;
|
|
83
|
-
}, "#getClock");
|
|
84
|
-
__name(_ClockAPI, "ClockAPI");
|
|
85
|
-
var ClockAPI = _ClockAPI;
|
|
86
|
-
|
|
87
|
-
// src/v3/clock-api.ts
|
|
88
|
-
var clock = ClockAPI.getInstance();
|
|
89
|
-
async function unboundedTimeout(delay = 0, value, options) {
|
|
90
|
-
const maxDelay = 2147483647;
|
|
91
|
-
const fullTimeouts = Math.floor(delay / maxDelay);
|
|
92
|
-
const remainingDelay = delay % maxDelay;
|
|
93
|
-
let lastTimeoutResult = await promises.setTimeout(remainingDelay, value, options);
|
|
94
|
-
for (let i = 0; i < fullTimeouts; i++) {
|
|
95
|
-
lastTimeoutResult = await promises.setTimeout(maxDelay, value, options);
|
|
96
|
-
}
|
|
97
|
-
return lastTimeoutResult;
|
|
98
|
-
}
|
|
99
|
-
__name(unboundedTimeout, "unboundedTimeout");
|
|
100
|
-
|
|
101
|
-
// src/v3/runtime/prodRuntimeManager.ts
|
|
102
|
-
var _ProdRuntimeManager = class _ProdRuntimeManager {
|
|
103
|
-
constructor(ipc, options = {}) {
|
|
104
|
-
this.ipc = ipc;
|
|
105
|
-
this.options = options;
|
|
106
|
-
this._taskWaits = /* @__PURE__ */ new Map();
|
|
107
|
-
this._batchWaits = /* @__PURE__ */ new Map();
|
|
108
|
-
}
|
|
109
|
-
disable() {
|
|
110
|
-
}
|
|
111
|
-
async waitForDuration(ms) {
|
|
112
|
-
const now = Date.now();
|
|
113
|
-
const resolveAfterDuration = unboundedTimeout(ms, "duration");
|
|
114
|
-
if (ms <= this.waitThresholdInMs) {
|
|
115
|
-
await resolveAfterDuration;
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const waitForRestore = new Promise((resolve, reject) => {
|
|
119
|
-
this._waitForRestore = {
|
|
120
|
-
resolve,
|
|
121
|
-
reject
|
|
122
|
-
};
|
|
123
|
-
});
|
|
124
|
-
const { willCheckpointAndRestore } = await this.ipc.sendWithAck("WAIT_FOR_DURATION", {
|
|
125
|
-
ms,
|
|
126
|
-
now
|
|
127
|
-
});
|
|
128
|
-
if (!willCheckpointAndRestore) {
|
|
129
|
-
await resolveAfterDuration;
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
this.ipc.send("READY_FOR_CHECKPOINT", {});
|
|
133
|
-
await Promise.race([
|
|
134
|
-
waitForRestore,
|
|
135
|
-
resolveAfterDuration
|
|
136
|
-
]);
|
|
137
|
-
this.ipc.send("CANCEL_CHECKPOINT", {});
|
|
138
|
-
}
|
|
139
|
-
resumeAfterRestore() {
|
|
140
|
-
if (!this._waitForRestore) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
clock.reset();
|
|
144
|
-
this._waitForRestore.resolve("restore");
|
|
145
|
-
this._waitForRestore = void 0;
|
|
146
|
-
}
|
|
147
|
-
async waitUntil(date) {
|
|
148
|
-
return this.waitForDuration(date.getTime() - Date.now());
|
|
149
|
-
}
|
|
150
|
-
async waitForTask(params) {
|
|
151
|
-
const promise = new Promise((resolve) => {
|
|
152
|
-
this._taskWaits.set(params.id, {
|
|
153
|
-
resolve
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
await this.ipc.send("WAIT_FOR_TASK", {
|
|
157
|
-
friendlyId: params.id
|
|
158
|
-
});
|
|
159
|
-
const result = await promise;
|
|
160
|
-
clock.reset();
|
|
161
|
-
return result;
|
|
162
|
-
}
|
|
163
|
-
async waitForBatch(params) {
|
|
164
|
-
if (!params.runs.length) {
|
|
165
|
-
return Promise.resolve({
|
|
166
|
-
id: params.id,
|
|
167
|
-
items: []
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
const promise = Promise.all(params.runs.map((runId) => {
|
|
171
|
-
return new Promise((resolve, reject) => {
|
|
172
|
-
this._taskWaits.set(runId, {
|
|
173
|
-
resolve
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
}));
|
|
177
|
-
await this.ipc.send("WAIT_FOR_BATCH", {
|
|
178
|
-
batchFriendlyId: params.id,
|
|
179
|
-
runFriendlyIds: params.runs
|
|
180
|
-
});
|
|
181
|
-
const results = await promise;
|
|
182
|
-
clock.reset();
|
|
183
|
-
return {
|
|
184
|
-
id: params.id,
|
|
185
|
-
items: results
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
resumeTask(completion, execution) {
|
|
189
|
-
const wait = this._taskWaits.get(execution.run.id);
|
|
190
|
-
if (!wait) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
wait.resolve(completion);
|
|
194
|
-
this._taskWaits.delete(execution.run.id);
|
|
195
|
-
}
|
|
196
|
-
get waitThresholdInMs() {
|
|
197
|
-
return this.options.waitThresholdInMs ?? 3e4;
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
__name(_ProdRuntimeManager, "ProdRuntimeManager");
|
|
201
|
-
var ProdRuntimeManager = _ProdRuntimeManager;
|
|
202
|
-
|
|
203
|
-
exports.ProdRuntimeManager = ProdRuntimeManager;
|
|
204
|
-
//# sourceMappingURL=out.js.map
|
|
205
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/v3/utils/platform.ts","../../../src/v3/utils/globals.ts","../../../src/v3/clock/simpleClock.ts","../../../src/v3/clock/index.ts","../../../src/v3/clock-api.ts","../../../src/v3/utils/timers.ts","../../../src/v3/runtime/prodRuntimeManager.ts"],"names":["_globalThis","globalThis","global","GLOBAL_TRIGGER_DOT_DEV_KEY","Symbol","for","_global","registerGlobal","type","instance","allowOverride","api","err","Error","getGlobal","PreciseDate","SimpleClock","preciseNow","now","nowStruct","toStruct","seconds","nanos","reset","API_NAME","SIMPLE_CLOCK","ClockAPI","getInstance","_instance","setGlobalClock","clock","setTimeout","unboundedTimeout","delay","value","options","maxDelay","fullTimeouts","Math","floor","remainingDelay","lastTimeoutResult","i","ProdRuntimeManager","constructor","ipc","_taskWaits","Map","_batchWaits","disable","waitForDuration","ms","Date","resolveAfterDuration","waitThresholdInMs","waitForRestore","Promise","resolve","reject","_waitForRestore","willCheckpointAndRestore","sendWithAck","send","race","resumeAfterRestore","undefined","waitUntil","date","getTime","waitForTask","params","promise","set","id","friendlyId","result","waitForBatch","runs","length","items","all","map","runId","batchFriendlyId","runFriendlyIds","results","resumeTask","completion","execution","wait","get","run","delete"],"mappings":";;;;;;;;;;;;;;;;;AAAO,IAAMA,cAAc,OAAOC,eAAe,WAAWA,aAAaC;;;ACKzE,IAAMC,6BAA6BC,OAAOC,IAAI,oBAAoB;AAElE,IAAMC,UAAUN;AAET,SAASO,eACdC,MACAC,UACAC,gBAAgB,OACP;AACT,QAAMC,MAAOL,QAAQH,0BAAAA,IAA8BG,QAAQH,0BAAAA,KAA+B,CAAC;AAE3F,MAAI,CAACO,iBAAiBC,IAAIH,IAAAA,GAAO;AAE/B,UAAMI,MAAM,IAAIC,MAAM,yDAAyDL,IAAAA,EAAM;AACrF,WAAO;EACT;AAEAG,MAAIH,IAAAA,IAAQC;AAEZ,SAAO;AACT;AAhBgBF;AAkBT,SAASO,UACdN,MAC0C;AAC1C,SAAOF,QAAQH,0BAAAA,IAA8BK,IAAAA;AAC/C;AAJgBM;;;AC3BhB,SAASC,mBAAmB;AAGrB,IAAMC,eAAN,MAAMA,aAAAA;EACXC,aAA+B;AAC7B,UAAMC,MAAM,IAAIH,YAAAA;AAChB,UAAMI,YAAYD,IAAIE,SAAQ;AAE9B,WAAO;MAACD,UAAUE;MAASF,UAAUG;;EACvC;EAEAC,QAAQ;EAER;AACF;AAXaP;AAAN,IAAMA,cAAN;;;ACHP,IAAMQ,WAAW;AAMjB,IAAMC,eAAe,IAAIT,YAAAA;AANzB;AAQO,IAAMU,YAAN,MAAMA,UAAAA;EAGX,cAAsB;AAsBtB;EAtBuB;EAEvB,OAAcC,cAAwB;AACpC,QAAI,CAAC,KAAKC,WAAW;AACnB,WAAKA,YAAY,I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iBb,OAAOG;MACxBW,gBAAgBd,OAAOO;IACzB,CAAA;AAEA,UAAMQ,UAAU,MAAMd;AAEtBzC,UAAMP,MAAK;AAEX,WAAO;MACLkD,IAAIH,OAAOG;MACXM,OAAOM;IACT;EACF;EAEAC,WAAWC,YAAoCC,WAAmC;AAChF,UAAMC,OAAO,KAAK3C,WAAW4C,IAAIF,UAAUG,IAAIlB,EAAE;AAEjD,QAAI,CAACgB,MAAM;AACT;IACF;AAEAA,SAAKhC,QAAQ8B,UAAAA;AAEb,SAAKzC,WAAW8C,OAAOJ,UAAUG,IAAIlB,EAAE;EACzC;EAEA,IAAYnB,oBAA4B;AACtC,WAAO,KAAKnB,QAAQmB,qBAAqB;EAC3C;AACF;AAtIaX;AAAN,IAAMA,qBAAN","sourcesContent":["export const _globalThis = typeof globalThis === \"object\" ? globalThis : global;\n","import { Clock } from \"../clock/clock\";\nimport type { RuntimeManager } from \"../runtime/manager\";\nimport { TaskCatalog } from \"../task-catalog/catalog\";\nimport { _globalThis } from \"./platform\";\n\nconst GLOBAL_TRIGGER_DOT_DEV_KEY = Symbol.for(`dev.trigger.ts.api`);\n\nconst _global = _globalThis as TriggerDotDevGlobal;\n\nexport function registerGlobal<Type extends keyof TriggerDotDevGlobalAPI>(\n type: Type,\n instance: TriggerDotDevGlobalAPI[Type],\n allowOverride = false\n): boolean {\n const api = (_global[GLOBAL_TRIGGER_DOT_DEV_KEY] = _global[GLOBAL_TRIGGER_DOT_DEV_KEY] ?? {});\n\n if (!allowOverride && api[type]) {\n // already registered an API of this type\n const err = new Error(`trigger.dev: Attempted duplicate registration of API: ${type}`);\n return false;\n }\n\n api[type] = instance;\n\n return true;\n}\n\nexport function getGlobal<Type extends keyof TriggerDotDevGlobalAPI>(\n type: Type\n): TriggerDotDevGlobalAPI[Type] | undefined {\n return _global[GLOBAL_TRIGGER_DOT_DEV_KEY]?.[type];\n}\n\nexport function unregisterGlobal(type: keyof TriggerDotDevGlobalAPI) {\n const api = _global[GLOBAL_TRIGGER_DOT_DEV_KEY];\n\n if (api) {\n delete api[type];\n }\n}\n\ntype TriggerDotDevGlobal = {\n [GLOBAL_TRIGGER_DOT_DEV_KEY]?: TriggerDotDevGlobalAPI;\n};\n\ntype TriggerDotDevGlobalAPI = {\n runtime?: RuntimeManager;\n logger?: any;\n clock?: Clock;\n [\"task-catalog\"]?: TaskCatalog;\n};\n","import { PreciseDate } from \"@google-cloud/precise-date\";\nimport { Clock } from \"./clock\";\n\nexport class SimpleClock implements Clock {\n preciseNow(): [number, number] {\n const now = new PreciseDate();\n const nowStruct = now.toStruct();\n\n return [nowStruct.seconds, nowStruct.nanos];\n }\n\n reset() {\n // do nothing\n }\n}\n","const API_NAME = \"clock\";\n\nimport { getGlobal, registerGlobal } from \"../utils/globals\";\nimport type { Clock, ClockTime } from \"./clock\";\nimport { SimpleClock } from \"./simpleClock\";\n\nconst SIMPLE_CLOCK = new SimpleClock();\n\nexport class ClockAPI {\n private static _instance?: ClockAPI;\n\n private constructor() {}\n\n public static getInstance(): ClockAPI {\n if (!this._instance) {\n this._instance = new ClockAPI();\n }\n\n return this._instance;\n }\n\n public setGlobalClock(clock: Clock): boolean {\n return registerGlobal(API_NAME, clock);\n }\n\n public preciseNow(): ClockTime {\n return this.#getClock().preciseNow();\n }\n\n public reset(): void {\n this.#getClock().reset();\n }\n\n #getClock(): Clock {\n return getGlobal(API_NAME) ?? SIMPLE_CLOCK;\n }\n}\n","// Split module-level variable definition into separate files to allow\n// tree-shaking on each api instance.\nimport { ClockAPI } from \"./clock\";\n/** Entrypoint for clock API */\nexport const clock = ClockAPI.getInstance();\n","import { TimerOptions } from \"node:timers\";\nimport { setTimeout } from \"node:timers/promises\";\n\nexport async function unboundedTimeout<T = void>(\n delay: number = 0,\n value?: T,\n options?: TimerOptions\n): Promise<T> {\n const maxDelay = 2147483647; // Highest value that will fit in a 32-bit signed integer\n\n const fullTimeouts = Math.floor(delay / maxDelay);\n const remainingDelay = delay % maxDelay;\n\n let lastTimeoutResult = await setTimeout(remainingDelay, value, options);\n\n for (let i = 0; i < fullTimeouts; i++) {\n lastTimeoutResult = await setTimeout(maxDelay, value, options);\n }\n\n return lastTimeoutResult;\n}\n","import { clock } from \"../clock-api\";\nimport {\n BatchTaskRunExecutionResult,\n ProdChildToWorkerMessages,\n ProdWorkerToChildMessages,\n TaskRunContext,\n TaskRunExecution,\n TaskRunExecutionResult,\n} from \"../schemas\";\nimport { unboundedTimeout } from \"../utils/timers\";\nimport { ZodIpcConnection } from \"../zodIpc\";\nimport { RuntimeManager } from \"./manager\";\n\nexport type ProdRuntimeManagerOptions = {\n waitThresholdInMs?: number;\n};\n\nexport class ProdRuntimeManager implements RuntimeManager {\n _taskWaits: Map<string, { resolve: (value: TaskRunExecutionResult) => void }> = new Map();\n\n _batchWaits: Map<\n string,\n { resolve: (value: BatchTaskRunExecutionResult) => void; reject: (err?: any) => void }\n > = new Map();\n\n _waitForRestore: { resolve: (value: \"restore\") => void; reject: (err?: any) => void } | undefined;\n\n constructor(\n private ipc: ZodIpcConnection<\n typeof ProdWorkerToChildMessages,\n typeof ProdChildToWorkerMessages\n >,\n private options: ProdRuntimeManagerOptions = {}\n ) {}\n\n disable(): void {\n // do nothing\n }\n\n async waitForDuration(ms: number): Promise<void> {\n const now = Date.now();\n\n const resolveAfterDuration = unboundedTimeout(ms, \"duration\" as const);\n\n if (ms <= this.waitThresholdInMs) {\n await resolveAfterDuration;\n return;\n }\n\n const waitForRestore = new Promise<\"restore\">((resolve, reject) => {\n this._waitForRestore = { resolve, reject };\n });\n\n const { willCheckpointAndRestore } = await this.ipc.sendWithAck(\"WAIT_FOR_DURATION\", {\n ms,\n now,\n });\n\n if (!willCheckpointAndRestore) {\n await resolveAfterDuration;\n return;\n }\n\n this.ipc.send(\"READY_FOR_CHECKPOINT\", {});\n\n // Don't wait for checkpoint beyond the requested wait duration\n await Promise.race([waitForRestore, resolveAfterDuration]);\n\n // The coordinator can then cancel any in-progress checkpoints\n this.ipc.send(\"CANCEL_CHECKPOINT\", {});\n }\n\n resumeAfterRestore(): void {\n if (!this._waitForRestore) {\n return;\n }\n\n // Resets the clock to the current time\n clock.reset();\n\n this._waitForRestore.resolve(\"restore\");\n this._waitForRestore = undefined;\n }\n\n async waitUntil(date: Date): Promise<void> {\n return this.waitForDuration(date.getTime() - Date.now());\n }\n\n async waitForTask(params: { id: string; ctx: TaskRunContext }): Promise<TaskRunExecutionResult> {\n const promise = new Promise<TaskRunExecutionResult>((resolve) => {\n this._taskWaits.set(params.id, { resolve });\n });\n\n await this.ipc.send(\"WAIT_FOR_TASK\", {\n friendlyId: params.id,\n });\n\n const result = await promise;\n\n clock.reset();\n\n return result;\n }\n\n async waitForBatch(params: {\n id: string;\n runs: string[];\n ctx: TaskRunContext;\n }): Promise<BatchTaskRunExecutionResult> {\n if (!params.runs.length) {\n return Promise.resolve({ id: params.id, items: [] });\n }\n\n const promise = Promise.all(\n params.runs.map((runId) => {\n return new Promise<TaskRunExecutionResult>((resolve, reject) => {\n this._taskWaits.set(runId, { resolve });\n });\n })\n );\n\n await this.ipc.send(\"WAIT_FOR_BATCH\", {\n batchFriendlyId: params.id,\n runFriendlyIds: params.runs,\n });\n\n const results = await promise;\n\n clock.reset();\n\n return {\n id: params.id,\n items: results,\n };\n }\n\n resumeTask(completion: TaskRunExecutionResult, execution: TaskRunExecution): void {\n const wait = this._taskWaits.get(execution.run.id);\n\n if (!wait) {\n return;\n }\n\n wait.resolve(completion);\n\n this._taskWaits.delete(execution.run.id);\n }\n\n private get waitThresholdInMs(): number {\n return this.options.waitThresholdInMs ?? 30_000;\n }\n}\n"]}
|