1
- import { RetryOptions , TaskMetadata , TaskRunContext } from "../schemas/index.js" ;
2
- import { Prettify } from "./utils.js" ;
3
-
4
1
export * from "./utils.js" ;
5
2
export * from "./tasks.js" ;
6
3
export * from "./idempotencyKeys.js" ;
7
4
8
- export type InitOutput = Record < string , any > | void | undefined ;
9
-
10
- export type RunFnParams < TInitOutput extends InitOutput > = Prettify < {
11
- /** Metadata about the task, run, attempt, queue, environment, organization, project and batch. */
12
- ctx : Context ;
13
- /** If you use the `init` function, this will be whatever you returned. */
14
- init ?: TInitOutput ;
15
- /** Abort signal that is aborted when a task run exceeds it's maxDuration. Can be used to automatically cancel downstream requests */
16
- signal ?: AbortSignal ;
17
- } > ;
18
-
19
- export type MiddlewareFnParams = Prettify < {
20
- ctx : Context ;
21
- next : ( ) => Promise < void > ;
22
- /** Abort signal that is aborted when a task run exceeds it's maxDuration. Can be used to automatically cancel downstream requests */
23
- signal ?: AbortSignal ;
24
- } > ;
25
-
26
- export type InitFnParams = Prettify < {
27
- ctx : Context ;
28
- /** Abort signal that is aborted when a task run exceeds it's maxDuration. Can be used to automatically cancel downstream requests */
29
- signal ?: AbortSignal ;
30
- } > ;
31
-
32
- export type StartFnParams = Prettify < {
33
- ctx : Context ;
34
- /** Abort signal that is aborted when a task run exceeds it's maxDuration. Can be used to automatically cancel downstream requests */
35
- signal ?: AbortSignal ;
36
- } > ;
37
-
38
- export type Context = TaskRunContext ;
39
-
40
- export type SuccessFnParams < TInitOutput extends InitOutput > = RunFnParams < TInitOutput > ;
41
-
42
- export type FailureFnParams < TInitOutput extends InitOutput > = RunFnParams < TInitOutput > ;
43
-
44
- export type HandleErrorFnParams < TInitOutput extends InitOutput > = RunFnParams < TInitOutput > &
45
- Prettify < {
46
- retry ?: RetryOptions ;
47
- retryAt ?: Date ;
48
- retryDelayInMs ?: number ;
49
- } > ;
50
-
51
- export type HandleErrorModificationOptions = {
52
- skipRetrying ?: boolean | undefined ;
53
- retryAt ?: Date | undefined ;
54
- retryDelayInMs ?: number | undefined ;
55
- retry ?: RetryOptions | undefined ;
56
- error ?: unknown ;
57
- } ;
58
-
59
- export type HandleErrorResult =
60
- | undefined
61
- | void
62
- | HandleErrorModificationOptions
63
- | Promise < undefined | void | HandleErrorModificationOptions > ;
64
-
65
- export type HandleErrorArgs = {
66
- ctx : Context ;
67
- retry ?: RetryOptions ;
68
- retryAt ?: Date ;
69
- retryDelayInMs ?: number ;
70
- /** Abort signal that is aborted when a task run exceeds it's maxDuration. Can be used to automatically cancel downstream requests */
71
- signal ?: AbortSignal ;
72
- } ;
73
-
74
- export type HandleErrorFunction = (
75
- payload : any ,
76
- error : unknown ,
77
- params : HandleErrorArgs
78
- ) => HandleErrorResult ;
79
-
80
5
type ResolveEnvironmentVariablesOptions = {
81
6
variables : Record < string , string > | Array < { name : string ; value : string } > ;
82
7
override ?: boolean ;
@@ -97,20 +22,3 @@ export type ResolveEnvironmentVariablesParams = {
97
22
export type ResolveEnvironmentVariablesFunction = (
98
23
params : ResolveEnvironmentVariablesParams
99
24
) => ResolveEnvironmentVariablesResult ;
100
-
101
- export type TaskMetadataWithFunctions = TaskMetadata & {
102
- fns : {
103
- run : ( payload : any , params : RunFnParams < any > ) => Promise < any > ;
104
- init ?: ( payload : any , params : InitFnParams ) => Promise < InitOutput > ;
105
- cleanup ?: ( payload : any , params : RunFnParams < any > ) => Promise < void > ;
106
- middleware ?: ( payload : any , params : MiddlewareFnParams ) => Promise < void > ;
107
- handleError ?: (
108
- payload : any ,
109
- error : unknown ,
110
- params : HandleErrorFnParams < any >
111
- ) => HandleErrorResult ;
112
- onSuccess ?: ( payload : any , output : any , params : SuccessFnParams < any > ) => Promise < void > ;
113
- onFailure ?: ( payload : any , error : unknown , params : FailureFnParams < any > ) => Promise < void > ;
114
- onStart ?: ( payload : any , params : StartFnParams ) => Promise < void > ;
115
- } ;
116
- } ;
0 commit comments