@trigger.dev/core 3.0.0-beta.20 → 3.0.0-beta.21

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.
@@ -100,6 +100,22 @@ interface ProjectConfig {
100
100
  * Enable console logging while running the dev CLI. This will print out logs from console.log, console.warn, and console.error. By default all logs are sent to the trigger.dev backend, and not logged to the console.
101
101
  */
102
102
  enableConsoleLogging?: boolean;
103
+ /**
104
+ * Run before a task is executed, for all tasks. This is useful for setting up any global state that is needed for all tasks.
105
+ */
106
+ init?: (payload: unknown, params: InitFnParams) => void | Promise<void>;
107
+ /**
108
+ * onSuccess is called after the run function has successfully completed.
109
+ */
110
+ onSuccess?: (payload: unknown, output: unknown, params: SuccessFnParams<any>) => Promise<void>;
111
+ /**
112
+ * onFailure is called after a task run has failed (meaning the run function threw an error and won't be retried anymore)
113
+ */
114
+ onFailure?: (payload: unknown, error: unknown, params: FailureFnParams<any>) => Promise<void>;
115
+ /**
116
+ * onStart is called the first time a task is executed in a run (not before every retry)
117
+ */
118
+ onStart?: (payload: unknown, params: StartFnParams) => Promise<void>;
103
119
  }
104
120
 
105
121
  type InitOutput = Record<string, any> | void | undefined;
@@ -116,10 +132,12 @@ type MiddlewareFnParams = Prettify<{
116
132
  type InitFnParams = Prettify<{
117
133
  ctx: Context;
118
134
  }>;
119
- type Context = TaskRunContext;
120
- type SuccessFnParams<TOutput, TInitOutput extends InitOutput> = RunFnParams<TInitOutput> & Prettify<{
121
- output: TOutput;
135
+ type StartFnParams = Prettify<{
136
+ ctx: Context;
122
137
  }>;
138
+ type Context = TaskRunContext;
139
+ type SuccessFnParams<TInitOutput extends InitOutput> = RunFnParams<TInitOutput>;
140
+ type FailureFnParams<TInitOutput extends InitOutput> = RunFnParams<TInitOutput>;
123
141
  type HandleErrorFnParams<TInitOutput extends InitOutput> = RunFnParams<TInitOutput> & Prettify<{
124
142
  retry?: RetryOptions;
125
143
  retryAt?: Date;
@@ -147,6 +165,9 @@ type TaskMetadataWithFunctions = TaskMetadata & {
147
165
  cleanup?: (payload: any, params: RunFnParams<any>) => Promise<void>;
148
166
  middleware?: (payload: any, params: MiddlewareFnParams) => Promise<void>;
149
167
  handleError?: (payload: any, error: unknown, params: HandleErrorFnParams<any>) => HandleErrorResult;
168
+ onSuccess?: (payload: any, output: any, params: SuccessFnParams<any>) => Promise<void>;
169
+ onFailure?: (payload: any, error: unknown, params: FailureFnParams<any>) => Promise<void>;
170
+ onStart?: (payload: any, params: StartFnParams) => Promise<void>;
150
171
  };
151
172
  };
152
173
 
@@ -6643,4 +6664,4 @@ interface TaskCatalog {
6643
6664
  taskExists(id: string): boolean;
6644
6665
  }
6645
6666
 
6646
- export { type Clock as C, type HandleErrorFnParams as H, type InitOutput as I, type LogLevel as L, type MiddlewareFnParams as M, OtelTaskLogger as O, type Prettify as P, type ResolvedConfig as R, SharedQueueToClientMessages as S, type TaskLogger as T, WaitReason as W, type ClockTime as a, type TaskCatalog as b, type TaskMetadataWithFunctions as c, TriggerTracer as d, PostStartCauses as e, PreStopCauses as f, Config as g, ProviderToPlatformMessages as h, PlatformToProviderMessages as i, CoordinatorToPlatformMessages as j, PlatformToCoordinatorMessages as k, ClientToSharedQueueMessages as l, ProdWorkerToCoordinatorMessages as m, CoordinatorToProdWorkerMessages as n, ProdWorkerSocketData as o, type RunFnParams as p, type InitFnParams as q, type Context as r, type SuccessFnParams as s, type HandleErrorModificationOptions as t, type HandleErrorResult as u, type HandleErrorArgs as v, type HandleErrorFunction as w, type RequireKeys as x, type ProjectConfig as y, logLevels as z };
6667
+ export { logLevels as A, type Clock as C, type FailureFnParams as F, type HandleErrorFnParams as H, type InitOutput as I, type LogLevel as L, type MiddlewareFnParams as M, OtelTaskLogger as O, type Prettify as P, type ResolvedConfig as R, SharedQueueToClientMessages as S, type TaskLogger as T, WaitReason as W, type ClockTime as a, type TaskCatalog as b, type TaskMetadataWithFunctions as c, TriggerTracer as d, PostStartCauses as e, PreStopCauses as f, Config as g, ProviderToPlatformMessages as h, PlatformToProviderMessages as i, CoordinatorToPlatformMessages as j, PlatformToCoordinatorMessages as k, ClientToSharedQueueMessages as l, ProdWorkerToCoordinatorMessages as m, CoordinatorToProdWorkerMessages as n, ProdWorkerSocketData as o, type RunFnParams as p, type InitFnParams as q, type StartFnParams as r, type Context as s, type SuccessFnParams as t, type HandleErrorModificationOptions as u, type HandleErrorResult as v, type HandleErrorArgs as w, type HandleErrorFunction as x, type RequireKeys as y, type ProjectConfig as z };
@@ -100,6 +100,22 @@ interface ProjectConfig {
100
100
  * Enable console logging while running the dev CLI. This will print out logs from console.log, console.warn, and console.error. By default all logs are sent to the trigger.dev backend, and not logged to the console.
101
101
  */
102
102
  enableConsoleLogging?: boolean;
103
+ /**
104
+ * Run before a task is executed, for all tasks. This is useful for setting up any global state that is needed for all tasks.
105
+ */
106
+ init?: (payload: unknown, params: InitFnParams) => void | Promise<void>;
107
+ /**
108
+ * onSuccess is called after the run function has successfully completed.
109
+ */
110
+ onSuccess?: (payload: unknown, output: unknown, params: SuccessFnParams<any>) => Promise<void>;
111
+ /**
112
+ * onFailure is called after a task run has failed (meaning the run function threw an error and won't be retried anymore)
113
+ */
114
+ onFailure?: (payload: unknown, error: unknown, params: FailureFnParams<any>) => Promise<void>;
115
+ /**
116
+ * onStart is called the first time a task is executed in a run (not before every retry)
117
+ */
118
+ onStart?: (payload: unknown, params: StartFnParams) => Promise<void>;
103
119
  }
104
120
 
105
121
  type InitOutput = Record<string, any> | void | undefined;
@@ -116,10 +132,12 @@ type MiddlewareFnParams = Prettify<{
116
132
  type InitFnParams = Prettify<{
117
133
  ctx: Context;
118
134
  }>;
119
- type Context = TaskRunContext;
120
- type SuccessFnParams<TOutput, TInitOutput extends InitOutput> = RunFnParams<TInitOutput> & Prettify<{
121
- output: TOutput;
135
+ type StartFnParams = Prettify<{
136
+ ctx: Context;
122
137
  }>;
138
+ type Context = TaskRunContext;
139
+ type SuccessFnParams<TInitOutput extends InitOutput> = RunFnParams<TInitOutput>;
140
+ type FailureFnParams<TInitOutput extends InitOutput> = RunFnParams<TInitOutput>;
123
141
  type HandleErrorFnParams<TInitOutput extends InitOutput> = RunFnParams<TInitOutput> & Prettify<{
124
142
  retry?: RetryOptions;
125
143
  retryAt?: Date;
@@ -147,6 +165,9 @@ type TaskMetadataWithFunctions = TaskMetadata & {
147
165
  cleanup?: (payload: any, params: RunFnParams<any>) => Promise<void>;
148
166
  middleware?: (payload: any, params: MiddlewareFnParams) => Promise<void>;
149
167
  handleError?: (payload: any, error: unknown, params: HandleErrorFnParams<any>) => HandleErrorResult;
168
+ onSuccess?: (payload: any, output: any, params: SuccessFnParams<any>) => Promise<void>;
169
+ onFailure?: (payload: any, error: unknown, params: FailureFnParams<any>) => Promise<void>;
170
+ onStart?: (payload: any, params: StartFnParams) => Promise<void>;
150
171
  };
151
172
  };
152
173
 
@@ -6643,4 +6664,4 @@ interface TaskCatalog {
6643
6664
  taskExists(id: string): boolean;
6644
6665
  }
6645
6666
 
6646
- export { type Clock as C, type HandleErrorFnParams as H, type InitOutput as I, type LogLevel as L, type MiddlewareFnParams as M, OtelTaskLogger as O, type Prettify as P, type ResolvedConfig as R, SharedQueueToClientMessages as S, type TaskLogger as T, WaitReason as W, type ClockTime as a, type TaskCatalog as b, type TaskMetadataWithFunctions as c, TriggerTracer as d, PostStartCauses as e, PreStopCauses as f, Config as g, ProviderToPlatformMessages as h, PlatformToProviderMessages as i, CoordinatorToPlatformMessages as j, PlatformToCoordinatorMessages as k, ClientToSharedQueueMessages as l, ProdWorkerToCoordinatorMessages as m, CoordinatorToProdWorkerMessages as n, ProdWorkerSocketData as o, type RunFnParams as p, type InitFnParams as q, type Context as r, type SuccessFnParams as s, type HandleErrorModificationOptions as t, type HandleErrorResult as u, type HandleErrorArgs as v, type HandleErrorFunction as w, type RequireKeys as x, type ProjectConfig as y, logLevels as z };
6667
+ export { logLevels as A, type Clock as C, type FailureFnParams as F, type HandleErrorFnParams as H, type InitOutput as I, type LogLevel as L, type MiddlewareFnParams as M, OtelTaskLogger as O, type Prettify as P, type ResolvedConfig as R, SharedQueueToClientMessages as S, type TaskLogger as T, WaitReason as W, type ClockTime as a, type TaskCatalog as b, type TaskMetadataWithFunctions as c, TriggerTracer as d, PostStartCauses as e, PreStopCauses as f, Config as g, ProviderToPlatformMessages as h, PlatformToProviderMessages as i, CoordinatorToPlatformMessages as j, PlatformToCoordinatorMessages as k, ClientToSharedQueueMessages as l, ProdWorkerToCoordinatorMessages as m, CoordinatorToProdWorkerMessages as n, ProdWorkerSocketData as o, type RunFnParams as p, type InitFnParams as q, type StartFnParams as r, type Context as s, type SuccessFnParams as t, type HandleErrorModificationOptions as u, type HandleErrorResult as v, type HandleErrorArgs as w, type HandleErrorFunction as x, type RequireKeys as y, type ProjectConfig as z };
@@ -1,8 +1,8 @@
1
1
  import { z } from 'zod';
2
2
  import { T as TaskRunExecutionResult, B as BatchTaskRunExecutionResult, a as TaskRunError, b as TaskRunContext, R as RuntimeManager } from '../manager-M9GLDnhJ.mjs';
3
3
  export { h as TaskRun, c as TaskRunBuiltInError, d as TaskRunCustomErrorObject, f as TaskRunErrorCodes, p as TaskRunExecution, j as TaskRunExecutionAttempt, o as TaskRunExecutionBatch, k as TaskRunExecutionEnvironment, l as TaskRunExecutionOrganization, m as TaskRunExecutionProject, n as TaskRunExecutionQueue, q as TaskRunExecutionRetry, i as TaskRunExecutionTask, r as TaskRunFailedExecutionResult, g as TaskRunInternalError, e as TaskRunStringError, s as TaskRunSuccessfulExecutionResult } from '../manager-M9GLDnhJ.mjs';
4
- import { P as Prettify, C as Clock, a as ClockTime, T as TaskLogger, b as TaskCatalog, c as TaskMetadataWithFunctions, d as TriggerTracer } from '../catalog-A-D3UC6S.mjs';
5
- export { l as ClientToSharedQueueMessages, g as Config, r as Context, j as CoordinatorToPlatformMessages, n as CoordinatorToProdWorkerMessages, v as HandleErrorArgs, H as HandleErrorFnParams, w as HandleErrorFunction, t as HandleErrorModificationOptions, u as HandleErrorResult, q as InitFnParams, I as InitOutput, L as LogLevel, M as MiddlewareFnParams, k as PlatformToCoordinatorMessages, i as PlatformToProviderMessages, e as PostStartCauses, f as PreStopCauses, o as ProdWorkerSocketData, m as ProdWorkerToCoordinatorMessages, y as ProjectConfig, h as ProviderToPlatformMessages, x as RequireKeys, R as ResolvedConfig, p as RunFnParams, S as SharedQueueToClientMessages, s as SuccessFnParams, W as WaitReason } from '../catalog-A-D3UC6S.mjs';
4
+ import { P as Prettify, C as Clock, a as ClockTime, T as TaskLogger, b as TaskCatalog, c as TaskMetadataWithFunctions, d as TriggerTracer } from '../catalog-PA64uhhi.mjs';
5
+ export { l as ClientToSharedQueueMessages, g as Config, s as Context, j as CoordinatorToPlatformMessages, n as CoordinatorToProdWorkerMessages, F as FailureFnParams, w as HandleErrorArgs, H as HandleErrorFnParams, x as HandleErrorFunction, u as HandleErrorModificationOptions, v as HandleErrorResult, q as InitFnParams, I as InitOutput, L as LogLevel, M as MiddlewareFnParams, k as PlatformToCoordinatorMessages, i as PlatformToProviderMessages, e as PostStartCauses, f as PreStopCauses, o as ProdWorkerSocketData, m as ProdWorkerToCoordinatorMessages, z as ProjectConfig, h as ProviderToPlatformMessages, y as RequireKeys, R as ResolvedConfig, p as RunFnParams, S as SharedQueueToClientMessages, r as StartFnParams, t as SuccessFnParams, W as WaitReason } from '../catalog-PA64uhhi.mjs';
6
6
  import { Attributes, Span } from '@opentelemetry/api';
7
7
  import { B as BackgroundWorkerProperties, T as TaskFileMetadata, a as TaskMetadataWithFilePath, R as RetryOptions } from '../messages-AriaDDm0.mjs';
8
8
  export { g as BackgroundWorkerClientMessages, f as BackgroundWorkerServerMessages, E as EnvironmentType, F as FixedWindowRateLimit, c as Machine, M as MachineCpu, b as MachineMemory, m as ProdChildToWorkerMessages, P as ProdTaskRunExecution, e as ProdTaskRunExecutionPayload, n as ProdWorkerToChildMessages, Q as QueueOptions, i as RateLimitOptions, S as SlidingWindowRateLimit, j as TaskMetadata, k as TaskMetadataFailedToParseData, d as TaskRunExecutionPayload, U as UncaughtExceptionMessage, l as childToWorkerMessages, h as clientWebsocketMessages, s as serverWebsocketMessages, w as workerToChildMessages } from '../messages-AriaDDm0.mjs';
@@ -1,8 +1,8 @@
1
1
  import { z } from 'zod';
2
2
  import { T as TaskRunExecutionResult, B as BatchTaskRunExecutionResult, a as TaskRunError, b as TaskRunContext, R as RuntimeManager } from '../manager-M9GLDnhJ.js';
3
3
  export { h as TaskRun, c as TaskRunBuiltInError, d as TaskRunCustomErrorObject, f as TaskRunErrorCodes, p as TaskRunExecution, j as TaskRunExecutionAttempt, o as TaskRunExecutionBatch, k as TaskRunExecutionEnvironment, l as TaskRunExecutionOrganization, m as TaskRunExecutionProject, n as TaskRunExecutionQueue, q as TaskRunExecutionRetry, i as TaskRunExecutionTask, r as TaskRunFailedExecutionResult, g as TaskRunInternalError, e as TaskRunStringError, s as TaskRunSuccessfulExecutionResult } from '../manager-M9GLDnhJ.js';
4
- import { P as Prettify, C as Clock, a as ClockTime, T as TaskLogger, b as TaskCatalog, c as TaskMetadataWithFunctions, d as TriggerTracer } from '../catalog-TAZd4-TP.js';
5
- export { l as ClientToSharedQueueMessages, g as Config, r as Context, j as CoordinatorToPlatformMessages, n as CoordinatorToProdWorkerMessages, v as HandleErrorArgs, H as HandleErrorFnParams, w as HandleErrorFunction, t as HandleErrorModificationOptions, u as HandleErrorResult, q as InitFnParams, I as InitOutput, L as LogLevel, M as MiddlewareFnParams, k as PlatformToCoordinatorMessages, i as PlatformToProviderMessages, e as PostStartCauses, f as PreStopCauses, o as ProdWorkerSocketData, m as ProdWorkerToCoordinatorMessages, y as ProjectConfig, h as ProviderToPlatformMessages, x as RequireKeys, R as ResolvedConfig, p as RunFnParams, S as SharedQueueToClientMessages, s as SuccessFnParams, W as WaitReason } from '../catalog-TAZd4-TP.js';
4
+ import { P as Prettify, C as Clock, a as ClockTime, T as TaskLogger, b as TaskCatalog, c as TaskMetadataWithFunctions, d as TriggerTracer } from '../catalog-KJXg8k3W.js';
5
+ export { l as ClientToSharedQueueMessages, g as Config, s as Context, j as CoordinatorToPlatformMessages, n as CoordinatorToProdWorkerMessages, F as FailureFnParams, w as HandleErrorArgs, H as HandleErrorFnParams, x as HandleErrorFunction, u as HandleErrorModificationOptions, v as HandleErrorResult, q as InitFnParams, I as InitOutput, L as LogLevel, M as MiddlewareFnParams, k as PlatformToCoordinatorMessages, i as PlatformToProviderMessages, e as PostStartCauses, f as PreStopCauses, o as ProdWorkerSocketData, m as ProdWorkerToCoordinatorMessages, z as ProjectConfig, h as ProviderToPlatformMessages, y as RequireKeys, R as ResolvedConfig, p as RunFnParams, S as SharedQueueToClientMessages, r as StartFnParams, t as SuccessFnParams, W as WaitReason } from '../catalog-KJXg8k3W.js';
6
6
  import { Attributes, Span } from '@opentelemetry/api';
7
7
  import { B as BackgroundWorkerProperties, T as TaskFileMetadata, a as TaskMetadataWithFilePath, R as RetryOptions } from '../messages-AriaDDm0.js';
8
8
  export { g as BackgroundWorkerClientMessages, f as BackgroundWorkerServerMessages, E as EnvironmentType, F as FixedWindowRateLimit, c as Machine, M as MachineCpu, b as MachineMemory, m as ProdChildToWorkerMessages, P as ProdTaskRunExecution, e as ProdTaskRunExecutionPayload, n as ProdWorkerToChildMessages, Q as QueueOptions, i as RateLimitOptions, S as SlidingWindowRateLimit, j as TaskMetadata, k as TaskMetadataFailedToParseData, d as TaskRunExecutionPayload, U as UncaughtExceptionMessage, l as childToWorkerMessages, h as clientWebsocketMessages, s as serverWebsocketMessages, w as workerToChildMessages } from '../messages-AriaDDm0.js';