Skip to content

Commit 3ca5985

Browse files
committed
Hooks now all use the new types, and adding some spans
1 parent df9cad6 commit 3ca5985

File tree

12 files changed

+549
-610
lines changed

12 files changed

+549
-610
lines changed

apps/webapp/app/components/runs/v3/RunIcon.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ export function RunIcon({ name, className, spanName }: TaskIconProps) {
7878
return <InformationCircleIcon className={cn(className, "text-rose-500")} />;
7979
case "fatal":
8080
return <HandRaisedIcon className={cn(className, "text-rose-800")} />;
81+
case "task-middleware":
82+
return <InformationCircleIcon className={cn(className, "text-text-dimmed")} />;
83+
case "task-fn-run":
84+
return <InformationCircleIcon className={cn(className, "text-text-dimmed")} />;
85+
case "task-hook-init":
86+
return <InformationCircleIcon className={cn(className, "text-text-dimmed")} />;
87+
case "task-hook-onStart":
88+
return <InformationCircleIcon className={cn(className, "text-text-dimmed")} />;
89+
case "task-hook-onSuccess":
90+
return <InformationCircleIcon className={cn(className, "text-text-dimmed")} />;
91+
case "task-hook-onFailure":
92+
return <InformationCircleIcon className={cn(className, "text-text-dimmed")} />;
93+
case "task-hook-onComplete":
94+
return <InformationCircleIcon className={cn(className, "text-text-dimmed")} />;
95+
case "task-hook-onWait":
96+
return <InformationCircleIcon className={cn(className, "text-text-dimmed")} />;
97+
case "task-hook-onResume":
98+
return <InformationCircleIcon className={cn(className, "text-text-dimmed")} />;
99+
case "task-hook-catchError":
100+
return <InformationCircleIcon className={cn(className, "text-text-dimmed")} />;
101+
case "task-hook-cleanup":
102+
return <InformationCircleIcon className={cn(className, "text-text-dimmed")} />;
81103
}
82104

83105
return <InformationCircleIcon className={cn(className, "text-text-dimmed")} />;

packages/cli-v3/src/entryPoints/dev-run-worker.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
import type { Tracer } from "@opentelemetry/api";
22
import type { Logger } from "@opentelemetry/api-logs";
33
import {
4+
AnyOnCatchErrorHookFunction,
5+
AnyOnFailureHookFunction,
6+
AnyOnInitHookFunction,
7+
AnyOnStartHookFunction,
8+
AnyOnSuccessHookFunction,
49
apiClientManager,
510
clock,
611
ExecutorToWorkerMessageCatalog,
712
type HandleErrorFunction,
13+
lifecycleHooks,
14+
localsAPI,
815
logger,
916
LogLevel,
17+
resourceCatalog,
1018
runMetadata,
1119
runtime,
12-
resourceCatalog,
20+
runTimelineMetrics,
1321
TaskRunErrorCodes,
1422
TaskRunExecution,
1523
timeout,
1624
TriggerConfig,
1725
waitUntil,
1826
WorkerManifest,
1927
WorkerToExecutorMessageCatalog,
20-
runTimelineMetrics,
21-
lifecycleHooks,
22-
lifecycleHooksAdapters,
23-
localsAPI,
2428
} from "@trigger.dev/core/v3";
2529
import { TriggerTracer } from "@trigger.dev/core/v3/tracer";
2630
import {
@@ -32,17 +36,17 @@ import {
3236
logLevels,
3337
ManagedRuntimeManager,
3438
OtelTaskLogger,
39+
StandardLifecycleHooksManager,
40+
StandardLocalsManager,
3541
StandardMetadataManager,
3642
StandardResourceCatalog,
43+
StandardRunTimelineMetricsManager,
3744
StandardWaitUntilManager,
3845
TaskExecutor,
3946
TracingDiagnosticLogLevel,
4047
TracingSDK,
4148
usage,
4249
UsageTimeoutManager,
43-
StandardRunTimelineMetricsManager,
44-
StandardLifecycleHooksManager,
45-
StandardLocalsManager,
4650
} from "@trigger.dev/core/v3/workers";
4751
import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc";
4852
import { readFile } from "node:fs/promises";
@@ -184,35 +188,35 @@ async function bootstrap() {
184188
if (config.init) {
185189
lifecycleHooks.registerGlobalInitHook({
186190
id: "config",
187-
fn: lifecycleHooksAdapters.createInitHookAdapter(config.init),
191+
fn: config.init as AnyOnInitHookFunction,
188192
});
189193
}
190194

191195
if (config.onStart) {
192196
lifecycleHooks.registerGlobalStartHook({
193197
id: "config",
194-
fn: lifecycleHooksAdapters.createStartHookAdapter(config.onStart),
198+
fn: config.onStart as AnyOnStartHookFunction,
195199
});
196200
}
197201

198202
if (config.onSuccess) {
199203
lifecycleHooks.registerGlobalSuccessHook({
200204
id: "config",
201-
fn: lifecycleHooksAdapters.createSuccessHookAdapter(config.onSuccess),
205+
fn: config.onSuccess as AnyOnSuccessHookFunction,
202206
});
203207
}
204208

205209
if (config.onFailure) {
206210
lifecycleHooks.registerGlobalFailureHook({
207211
id: "config",
208-
fn: lifecycleHooksAdapters.createFailureHookAdapter(config.onFailure),
212+
fn: config.onFailure as AnyOnFailureHookFunction,
209213
});
210214
}
211215

212216
if (handleError) {
213217
lifecycleHooks.registerGlobalCatchErrorHook({
214218
id: "config",
215-
fn: lifecycleHooksAdapters.createHandleErrorHookAdapter(handleError),
219+
fn: handleError as AnyOnCatchErrorHookFunction,
216220
});
217221
}
218222

packages/cli-v3/src/entryPoints/managed-run-worker.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
import type { Tracer } from "@opentelemetry/api";
22
import type { Logger } from "@opentelemetry/api-logs";
33
import {
4+
AnyOnCatchErrorHookFunction,
5+
AnyOnFailureHookFunction,
6+
AnyOnInitHookFunction,
7+
AnyOnStartHookFunction,
8+
AnyOnSuccessHookFunction,
9+
apiClientManager,
410
clock,
11+
ExecutorToWorkerMessageCatalog,
512
type HandleErrorFunction,
13+
lifecycleHooks,
14+
localsAPI,
615
logger,
716
LogLevel,
8-
runtime,
917
resourceCatalog,
18+
runMetadata,
19+
runtime,
20+
runTimelineMetrics,
1021
TaskRunErrorCodes,
1122
TaskRunExecution,
12-
WorkerToExecutorMessageCatalog,
13-
TriggerConfig,
14-
WorkerManifest,
15-
ExecutorToWorkerMessageCatalog,
1623
timeout,
17-
runMetadata,
24+
TriggerConfig,
1825
waitUntil,
19-
apiClientManager,
20-
runTimelineMetrics,
21-
lifecycleHooks,
22-
lifecycleHooksAdapters,
23-
localsAPI,
26+
WorkerManifest,
27+
WorkerToExecutorMessageCatalog,
2428
} from "@trigger.dev/core/v3";
2529
import { TriggerTracer } from "@trigger.dev/core/v3/tracer";
2630
import {
@@ -30,20 +34,20 @@ import {
3034
getEnvVar,
3135
getNumberEnvVar,
3236
logLevels,
37+
ManagedRuntimeManager,
3338
OtelTaskLogger,
3439
ProdUsageManager,
40+
StandardLifecycleHooksManager,
41+
StandardLocalsManager,
42+
StandardMetadataManager,
3543
StandardResourceCatalog,
44+
StandardRunTimelineMetricsManager,
45+
StandardWaitUntilManager,
3646
TaskExecutor,
3747
TracingDiagnosticLogLevel,
3848
TracingSDK,
3949
usage,
4050
UsageTimeoutManager,
41-
StandardMetadataManager,
42-
StandardWaitUntilManager,
43-
ManagedRuntimeManager,
44-
StandardRunTimelineMetricsManager,
45-
StandardLifecycleHooksManager,
46-
StandardLocalsManager,
4751
} from "@trigger.dev/core/v3/workers";
4852
import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc";
4953
import { readFile } from "node:fs/promises";
@@ -194,35 +198,35 @@ async function bootstrap() {
194198
if (config.init) {
195199
lifecycleHooks.registerGlobalInitHook({
196200
id: "config",
197-
fn: lifecycleHooksAdapters.createInitHookAdapter(config.init),
201+
fn: config.init as AnyOnInitHookFunction,
198202
});
199203
}
200204

201205
if (config.onStart) {
202206
lifecycleHooks.registerGlobalStartHook({
203207
id: "config",
204-
fn: lifecycleHooksAdapters.createStartHookAdapter(config.onStart),
208+
fn: config.onStart as AnyOnStartHookFunction,
205209
});
206210
}
207211

208212
if (config.onSuccess) {
209213
lifecycleHooks.registerGlobalSuccessHook({
210214
id: "config",
211-
fn: lifecycleHooksAdapters.createSuccessHookAdapter(config.onSuccess),
215+
fn: config.onSuccess as AnyOnSuccessHookFunction,
212216
});
213217
}
214218

215219
if (config.onFailure) {
216220
lifecycleHooks.registerGlobalFailureHook({
217221
id: "config",
218-
fn: lifecycleHooksAdapters.createFailureHookAdapter(config.onFailure),
222+
fn: config.onFailure as AnyOnFailureHookFunction,
219223
});
220224
}
221225

222226
if (handleError) {
223227
lifecycleHooks.registerGlobalCatchErrorHook({
224228
id: "config",
225-
fn: lifecycleHooksAdapters.createHandleErrorHookAdapter(handleError),
229+
fn: handleError as AnyOnCatchErrorHookFunction,
226230
});
227231
}
228232

packages/core/src/v3/config.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import type { Instrumentation } from "@opentelemetry/instrumentation";
22
import type { SpanExporter } from "@opentelemetry/sdk-trace-base";
33
import type { BuildExtension } from "./build/extensions.js";
4-
import type { MachinePresetName } from "./schemas/common.js";
5-
import type { LogLevel } from "./logger/taskLogger.js";
64
import type {
7-
FailureFnParams,
8-
InitFnParams,
9-
StartFnParams,
10-
SuccessFnParams,
11-
} from "./types/index.js";
12-
import type { BuildRuntime, RetryOptions } from "./index.js";
5+
AnyOnFailureHookFunction,
6+
AnyOnInitHookFunction,
7+
AnyOnStartHookFunction,
8+
AnyOnSuccessHookFunction,
9+
BuildRuntime,
10+
RetryOptions,
11+
} from "./index.js";
12+
import type { LogLevel } from "./logger/taskLogger.js";
13+
import type { MachinePresetName } from "./schemas/common.js";
1314

1415
export type CompatibilityFlag = "run_engine_v2";
1516

@@ -215,23 +216,31 @@ export type TriggerConfig = {
215216

216217
/**
217218
* Run before a task is executed, for all tasks. This is useful for setting up any global state that is needed for all tasks.
219+
*
220+
* @deprecated, please use tasks.init instead
218221
*/
219-
init?: (payload: unknown, params: InitFnParams) => any | Promise<any>;
222+
init?: AnyOnInitHookFunction;
220223

221224
/**
222225
* onSuccess is called after the run function has successfully completed.
226+
*
227+
* @deprecated, please use tasks.onSuccess instead
223228
*/
224-
onSuccess?: (payload: unknown, output: unknown, params: SuccessFnParams<any>) => Promise<void>;
229+
onSuccess?: AnyOnSuccessHookFunction;
225230

226231
/**
227232
* onFailure is called after a task run has failed (meaning the run function threw an error and won't be retried anymore)
233+
*
234+
* @deprecated, please use tasks.onFailure instead
228235
*/
229-
onFailure?: (payload: unknown, error: unknown, params: FailureFnParams<any>) => Promise<void>;
236+
onFailure?: AnyOnFailureHookFunction;
230237

231238
/**
232239
* onStart is called the first time a task is executed in a run (not before every retry)
240+
*
241+
* @deprecated, please use tasks.onStart instead
233242
*/
234-
onStart?: (payload: unknown, params: StartFnParams) => Promise<void>;
243+
onStart?: AnyOnStartHookFunction;
235244

236245
/**
237246
* @deprecated Use a custom build extension to add post install commands

packages/core/src/v3/lifecycle-hooks-api.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,3 @@ export type {
3232
AnyOnCleanupHookFunction,
3333
TaskCleanupHookParams,
3434
} from "./lifecycleHooks/types.js";
35-
36-
export * as lifecycleHooksAdapters from "./lifecycleHooks/adapters.js";

0 commit comments

Comments
 (0)