@convex-dev/workpool 0.2.18-alpha.3 → 0.2.19-alpha.0
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/README.md +83 -76
- package/dist/commonjs/client/index.d.ts +98 -31
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +124 -49
- package/dist/commonjs/client/index.js.map +1 -1
- package/dist/commonjs/component/kick.d.ts.map +1 -1
- package/dist/commonjs/component/kick.js +2 -2
- package/dist/commonjs/component/kick.js.map +1 -1
- package/dist/commonjs/component/lib.d.ts +39 -1
- package/dist/commonjs/component/lib.d.ts.map +1 -1
- package/dist/commonjs/component/lib.js +92 -56
- package/dist/commonjs/component/lib.js.map +1 -1
- package/dist/esm/client/index.d.ts +98 -31
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +124 -49
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/component/kick.d.ts.map +1 -1
- package/dist/esm/component/kick.js +2 -2
- package/dist/esm/component/kick.js.map +1 -1
- package/dist/esm/component/lib.d.ts +39 -1
- package/dist/esm/component/lib.d.ts.map +1 -1
- package/dist/esm/component/lib.js +92 -56
- package/dist/esm/component/lib.js.map +1 -1
- package/package.json +15 -10
- package/src/client/index.ts +225 -82
- package/src/component/_generated/api.d.ts +34 -0
- package/src/component/kick.ts +3 -1
- package/src/component/lib.ts +108 -61
package/README.md
CHANGED
|
@@ -12,9 +12,7 @@ This Convex component pools actions and mutations to restrict parallel requests.
|
|
|
12
12
|
- An `onComplete` callback so you can build durable, reliable workflows. Called
|
|
13
13
|
when the work is finished, whether it succeeded, failed, or was canceled.
|
|
14
14
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
### Separating and throttling async workloads
|
|
15
|
+
## Separating and throttling async workloads
|
|
18
16
|
|
|
19
17
|
Suppose you have some important async work, like sending verification emails,
|
|
20
18
|
and some less important async work, like scraping data from an API. If all of
|
|
@@ -51,9 +49,9 @@ export const downloadLatestWeather = mutation({
|
|
|
51
49
|
});
|
|
52
50
|
```
|
|
53
51
|
|
|
54
|
-
|
|
52
|
+
## Durable, reliable workflows
|
|
55
53
|
|
|
56
|
-
|
|
54
|
+
### Retry management
|
|
57
55
|
|
|
58
56
|
Imagine that the payment processor is a 3rd party API, and they temporarily have an
|
|
59
57
|
outage. Now imagine you implement your own action retrying logic for your busy app.
|
|
@@ -65,7 +63,7 @@ Creating an upper bound on how much work will be done in parallel is a good way
|
|
|
65
63
|
mitigate this risk. Actions that are currently backing off awaiting retry will not tie
|
|
66
64
|
up a thread in the workpool.
|
|
67
65
|
|
|
68
|
-
|
|
66
|
+
### Completion handling
|
|
69
67
|
|
|
70
68
|
By handing off asynchronous work, it will be guaranteed to run, and with retries
|
|
71
69
|
you can account for temporary failures, while avoiding a "stampeding herd"
|
|
@@ -114,11 +112,16 @@ export const emailSent = internalMutation({
|
|
|
114
112
|
error: result.kind === "failed" ? result.error : null,
|
|
115
113
|
});
|
|
116
114
|
if (result.kind === "failed") {
|
|
117
|
-
await pool.enqueueAction(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
await pool.enqueueAction(
|
|
116
|
+
ctx,
|
|
117
|
+
internal.email.checkStatus,
|
|
118
|
+
{ userId },
|
|
119
|
+
{
|
|
120
|
+
retry: { maxAttempts: 10, initialBackoffMs: 250, base: 2 }, // custom
|
|
121
|
+
onComplete: internal.email.handleEmailStatus,
|
|
122
|
+
context: { emailLogId },
|
|
123
|
+
}
|
|
124
|
+
);
|
|
122
125
|
}
|
|
123
126
|
},
|
|
124
127
|
});
|
|
@@ -141,7 +144,7 @@ export const emailSent = pool.defineOnComplete<DataModel>({
|
|
|
141
144
|
});
|
|
142
145
|
```
|
|
143
146
|
|
|
144
|
-
|
|
147
|
+
### Idempotency
|
|
145
148
|
|
|
146
149
|
Idempotent actions are actions that can be run multiple times safely. This typically
|
|
147
150
|
means they don't cause any side effects that would be a problem if executed twice or more.
|
|
@@ -162,10 +165,10 @@ If you're creating complex workflows with many steps involving 3rd party APIs:
|
|
|
162
165
|
1. You should ensure that each step is an idempotent Convex action.
|
|
163
166
|
2. You should use this component to manage these actions so it all just works!
|
|
164
167
|
|
|
165
|
-
###
|
|
168
|
+
### Reducing database write conflicts (aka OCC errors)
|
|
166
169
|
|
|
167
170
|
With limited parallelism, you can reduce
|
|
168
|
-
[
|
|
171
|
+
[write conflicts](https://docs.convex.dev/error#1)
|
|
169
172
|
from mutations that read and write the same data.
|
|
170
173
|
|
|
171
174
|
Consider this action that calls a mutation to increment a singleton counter.
|
|
@@ -199,7 +202,44 @@ Effectively, Workpool runs async functions similar to
|
|
|
199
202
|
`ctx.scheduler.runAfter(0, ...)`, but it limits the number of functions that
|
|
200
203
|
can run in parallel.
|
|
201
204
|
|
|
202
|
-
##
|
|
205
|
+
## Reactive status of asynchronous work
|
|
206
|
+
|
|
207
|
+
The workpool stores the status of each function in the database, and thanks to
|
|
208
|
+
Convex's reactive queries, you can read it in a query to power a reactive UI.
|
|
209
|
+
|
|
210
|
+
By default, it will keep the status for 1 day but you can change this with
|
|
211
|
+
the `statusTtl` option to `Workpool`.
|
|
212
|
+
|
|
213
|
+
To keep the status forever, set `statusTtl: Number.POSITIVE_INFINITY`.
|
|
214
|
+
|
|
215
|
+
You can read the status of a function by calling `pool.status(id)`.
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
import { vWorkIdValidator } from "@convex-dev/workpool";
|
|
219
|
+
import { query } from "./_generated/server";
|
|
220
|
+
|
|
221
|
+
export const getStatus = query({
|
|
222
|
+
args: { id: vWorkIdValidator },
|
|
223
|
+
handler: async (ctx, args) => {
|
|
224
|
+
const status = await pool.status(args.id);
|
|
225
|
+
return status;
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
The status will be one of:
|
|
231
|
+
|
|
232
|
+
- `{ kind: "pending"; previousAttempts: number }`: The function has not started yet.
|
|
233
|
+
- `{ kind: "running"; previousAttempts: number }`: The function is currently running.
|
|
234
|
+
- `{ kind: "finished" }`: The function has succeeded, failed, or been canceled.
|
|
235
|
+
|
|
236
|
+
To get the result of your function, you can either write to the database from
|
|
237
|
+
within your function, call or schedule another function from there, or use the
|
|
238
|
+
`onComplete` handler to respond to the job result.
|
|
239
|
+
|
|
240
|
+
## Get started
|
|
241
|
+
|
|
242
|
+
### Pre-requisite: Convex
|
|
203
243
|
|
|
204
244
|
You'll need an existing Convex project to use the component.
|
|
205
245
|
Convex is a hosted backend platform, including a database, serverless functions,
|
|
@@ -207,7 +247,7 @@ and a ton more you can learn about [here](https://docs.convex.dev/get-started).
|
|
|
207
247
|
|
|
208
248
|
Run `npm create convex` or follow any of the [quickstarts](https://docs.convex.dev/home) to set one up.
|
|
209
249
|
|
|
210
|
-
|
|
250
|
+
### Install the component
|
|
211
251
|
|
|
212
252
|
See [`example/`](./example/convex/) for a working demo.
|
|
213
253
|
|
|
@@ -231,49 +271,7 @@ app.use(workpool, { name: "scrapeWorkpool" });
|
|
|
231
271
|
export default app;
|
|
232
272
|
```
|
|
233
273
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
```ts
|
|
237
|
-
import { components } from "./_generated/api";
|
|
238
|
-
import { Workpool } from "@convex-dev/workpool";
|
|
239
|
-
|
|
240
|
-
const pool = new Workpool(components.emailWorkpool, { maxParallelism: 10 });
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
Then you have the following interface on `pool`:
|
|
244
|
-
|
|
245
|
-
```ts
|
|
246
|
-
import { vWorkIdValidator } from "@convex-dev/workpool";
|
|
247
|
-
|
|
248
|
-
export const myMutation = mutation({
|
|
249
|
-
args: {},
|
|
250
|
-
handler: async (ctx, args) => {
|
|
251
|
-
// Schedule functions to run in the background.
|
|
252
|
-
const id = await pool.enqueueMutation(ctx, internal.foo.bar, args);
|
|
253
|
-
// Or for an action:
|
|
254
|
-
const id = await pool.enqueueAction(ctx, internal.foo.baz, args);
|
|
255
|
-
},
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
export const getStatus = query({
|
|
259
|
-
args: { id: vWorkIdValidator },
|
|
260
|
-
handler: async (ctx, args) => {
|
|
261
|
-
// Is it done yet? Did it succeed or fail?
|
|
262
|
-
const status = await pool.status(args.id);
|
|
263
|
-
return status;
|
|
264
|
-
},
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
export const cancelWork = mutation({
|
|
268
|
-
args: { id: vWorkIdValidator },
|
|
269
|
-
handler: async (ctx, args) => {
|
|
270
|
-
// You can cancel the work, if it hasn't finished yet.
|
|
271
|
-
await pool.cancel(ctx, args.id);
|
|
272
|
-
},
|
|
273
|
-
});
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
See more example usage in [example.ts](./example/convex/example.ts).
|
|
274
|
+
See example usage in [example.ts](./example/convex/example.ts).
|
|
277
275
|
|
|
278
276
|
### Configuring the Workpool
|
|
279
277
|
|
|
@@ -326,39 +324,48 @@ If you're running into issues with too many concurrent functions, there are
|
|
|
326
324
|
alternatives to Workpool:
|
|
327
325
|
|
|
328
326
|
- Try combining multiple mutations into a single mutation, with batching or
|
|
329
|
-
debouncing.
|
|
327
|
+
debouncing. See the next section for enqueueing multiple actions at once.
|
|
330
328
|
- Call plain TypeScript functions if possible.
|
|
331
329
|
- In particular, an action calling `ctx.runAction` has more overhead than just
|
|
332
330
|
calling the action's handler directly.
|
|
333
331
|
|
|
334
332
|
See [best practices](https://docs.convex.dev/production/best-practices) for more.
|
|
335
333
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
The workpool stores the status of each function in the database, so you can
|
|
339
|
-
read it even after the function has finished.
|
|
340
|
-
By default, it will keep the status for 1 day but you can change this with
|
|
341
|
-
the `statusTtl` option to `Workpool`.
|
|
342
|
-
|
|
343
|
-
To keep the status forever, set `statusTtl: Number.POSITIVE_INFINITY`.
|
|
334
|
+
### Batching
|
|
344
335
|
|
|
345
|
-
|
|
336
|
+
If you're enqueuing a lot of work, you can use `enqueueActionBatch` to enqueue
|
|
337
|
+
a batch of actions at once, or the equivalents for queries or mutations.
|
|
346
338
|
|
|
347
|
-
|
|
339
|
+
This helps in two ways:
|
|
348
340
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
341
|
+
1. It reduces the number of calls to the component, which reduces overhead
|
|
342
|
+
as each component call runs in a fresh container (for strong isolation).
|
|
343
|
+
2. When called from an action, it reduces the number of mutations that might
|
|
344
|
+
conflict with each other, especially if they were being called in parallel.
|
|
352
345
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
346
|
+
```ts
|
|
347
|
+
await pool.enqueueActionBatch(ctx, internal.weather.scrape, [
|
|
348
|
+
{ city: "New York" },
|
|
349
|
+
{ city: "Los Angeles" },
|
|
350
|
+
{ city: "Chicago" },
|
|
351
|
+
]);
|
|
352
|
+
```
|
|
356
353
|
|
|
357
354
|
## Canceling work
|
|
358
355
|
|
|
359
356
|
You can cancel work by calling `pool.cancel(id)` or all of them with
|
|
360
357
|
`pool.cancelAll()`.
|
|
361
358
|
|
|
359
|
+
```ts
|
|
360
|
+
export const cancelWork = mutation({
|
|
361
|
+
args: { id: vWorkIdValidator },
|
|
362
|
+
handler: async (ctx, args) => {
|
|
363
|
+
// You can cancel the work, if it hasn't finished yet.
|
|
364
|
+
await pool.cancel(ctx, args.id);
|
|
365
|
+
},
|
|
366
|
+
});
|
|
367
|
+
```
|
|
368
|
+
|
|
362
369
|
This will avoid starting or retrying, but will not stop in-progress work.
|
|
363
370
|
|
|
364
371
|
## Monitoring the workpool
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DefaultFunctionArgs, FunctionReference, FunctionVisibility, GenericDataModel, GenericMutationCtx, RegisteredMutation } from "convex/server";
|
|
1
|
+
import { DefaultFunctionArgs, FunctionReference, FunctionType, FunctionVisibility, GenericDataModel, GenericMutationCtx, RegisteredMutation } from "convex/server";
|
|
2
2
|
import { Infer, Validator, VAny, VString } from "convex/values";
|
|
3
3
|
import { Mounts } from "../component/_generated/api.js";
|
|
4
4
|
import { type LogLevel } from "../component/logging.js";
|
|
@@ -61,8 +61,9 @@ export declare const vOnComplete: import("convex/values").VObject<{
|
|
|
61
61
|
/** @deprecated Use `vOnCompleteArgs()` instead. */
|
|
62
62
|
export declare const vOnCompleteValidator: typeof vOnCompleteArgs;
|
|
63
63
|
export declare const DEFAULT_RETRY_BEHAVIOR: RetryBehavior;
|
|
64
|
+
export type WorkpoolComponent = UseApi<Mounts>;
|
|
64
65
|
export declare class Workpool {
|
|
65
|
-
|
|
66
|
+
component: WorkpoolComponent;
|
|
66
67
|
options: WorkpoolOptions;
|
|
67
68
|
/**
|
|
68
69
|
* Initializes a Workpool.
|
|
@@ -75,8 +76,7 @@ export declare class Workpool {
|
|
|
75
76
|
* `./_generated/api.ts`.
|
|
76
77
|
* @param options - The {@link WorkpoolOptions} for the Workpool.
|
|
77
78
|
*/
|
|
78
|
-
constructor(component:
|
|
79
|
-
options: WorkpoolOptions);
|
|
79
|
+
constructor(component: WorkpoolComponent, options: WorkpoolOptions);
|
|
80
80
|
/**
|
|
81
81
|
* Enqueues an action to be run.
|
|
82
82
|
*
|
|
@@ -87,7 +87,20 @@ export declare class Workpool {
|
|
|
87
87
|
* onComplete handling, and scheduling via `runAt` or `runAfter`.
|
|
88
88
|
* @returns The ID of the work that was enqueued.
|
|
89
89
|
*/
|
|
90
|
-
enqueueAction<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"action", FunctionVisibility, Args, ReturnType>, fnArgs: Args, options?: RetryOption &
|
|
90
|
+
enqueueAction<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"action", FunctionVisibility, Args, ReturnType>, fnArgs: Args, options?: RetryOption & EnqueueOptions): Promise<WorkId>;
|
|
91
|
+
/**
|
|
92
|
+
* Enqueues a batch of actions to be run.
|
|
93
|
+
* Each action will be run independently, and the onComplete handler will
|
|
94
|
+
* be called for each action.
|
|
95
|
+
*
|
|
96
|
+
* @param ctx - The mutation or action ctx that can call ctx.runMutation.
|
|
97
|
+
* @param fn - The action to run, like `internal.example.myAction`.
|
|
98
|
+
* @param argsArray - The arguments to pass to the action.
|
|
99
|
+
* @param options - The options for the actions to specify retry behavior,
|
|
100
|
+
* onComplete handling, and scheduling via `runAt` or `runAfter`.
|
|
101
|
+
* @returns The IDs of the work that was enqueued.
|
|
102
|
+
*/
|
|
103
|
+
enqueueActionBatch<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"action", FunctionVisibility, Args, ReturnType>, argsArray: Array<Args>, options?: RetryOption & EnqueueOptions): Promise<WorkId[]>;
|
|
91
104
|
/**
|
|
92
105
|
* Enqueues a mutation to be run.
|
|
93
106
|
*
|
|
@@ -101,8 +114,44 @@ export declare class Workpool {
|
|
|
101
114
|
* @param options - The options for the mutation to specify onComplete handling
|
|
102
115
|
* and scheduling via `runAt` or `runAfter`.
|
|
103
116
|
*/
|
|
104
|
-
enqueueMutation<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"mutation", FunctionVisibility, Args, ReturnType>, fnArgs: Args, options?:
|
|
105
|
-
|
|
117
|
+
enqueueMutation<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"mutation", FunctionVisibility, Args, ReturnType>, fnArgs: Args, options?: EnqueueOptions): Promise<WorkId>;
|
|
118
|
+
/**
|
|
119
|
+
* Enqueues a batch of mutations to be run.
|
|
120
|
+
* Each mutation will be run independently, and the onComplete handler will
|
|
121
|
+
* be called for each mutation.
|
|
122
|
+
*
|
|
123
|
+
* @param ctx - The mutation or action context that can call ctx.runMutation.
|
|
124
|
+
* @param fn - The mutation to run, like `internal.example.myMutation`.
|
|
125
|
+
* @param argsArray - The arguments to pass to the mutations.
|
|
126
|
+
* @param options - The options for the mutations to specify onComplete handling
|
|
127
|
+
* and scheduling via `runAt` or `runAfter`.
|
|
128
|
+
*/
|
|
129
|
+
enqueueMutationBatch<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"mutation", FunctionVisibility, Args, ReturnType>, argsArray: Array<Args>, options?: EnqueueOptions): Promise<WorkId[]>;
|
|
130
|
+
/**
|
|
131
|
+
* Enqueues a query to be run.
|
|
132
|
+
* Usually not what you want, but it can be useful during workflows.
|
|
133
|
+
* The query is run in a mutation and the result is returned to the caller,
|
|
134
|
+
* so it can conflict if other mutations are writing the value.
|
|
135
|
+
*
|
|
136
|
+
* @param ctx - The mutation or action context that can call ctx.runMutation.
|
|
137
|
+
* @param fn - The query to run, like `internal.example.myQuery`.
|
|
138
|
+
* @param fnArgs - The arguments to pass to the query.
|
|
139
|
+
* @param options - The options for the query to specify onComplete handling
|
|
140
|
+
* and scheduling via `runAt` or `runAfter`.
|
|
141
|
+
*/
|
|
142
|
+
enqueueQuery<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"query", FunctionVisibility, Args, ReturnType>, fnArgs: Args, options?: EnqueueOptions): Promise<WorkId>;
|
|
143
|
+
/**
|
|
144
|
+
* Enqueues a batch of queries to be run.
|
|
145
|
+
* Each query will be run independently, and the onComplete handler will
|
|
146
|
+
* be called for each query.
|
|
147
|
+
*
|
|
148
|
+
* @param ctx - The mutation or action context that can call ctx.runMutation.
|
|
149
|
+
* @param fn - The query to run, like `internal.example.myQuery`.
|
|
150
|
+
* @param argsArray - The arguments to pass to the queries.
|
|
151
|
+
* @param options - The options for the queries to specify onComplete handling
|
|
152
|
+
* and scheduling via `runAt` or `runAfter`.
|
|
153
|
+
*/
|
|
154
|
+
enqueueQueryBatch<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"query", FunctionVisibility, Args, ReturnType>, argsArray: Array<Args>, options?: EnqueueOptions): Promise<WorkId[]>;
|
|
106
155
|
/**
|
|
107
156
|
* Cancels a work item. If it's already started, it will be allowed to finish
|
|
108
157
|
* but will not be retried.
|
|
@@ -116,7 +165,9 @@ export declare class Workpool {
|
|
|
116
165
|
*
|
|
117
166
|
* @param ctx - The mutation or action context that can call ctx.runMutation.
|
|
118
167
|
*/
|
|
119
|
-
cancelAll(ctx: RunMutationCtx
|
|
168
|
+
cancelAll(ctx: RunMutationCtx, options?: {
|
|
169
|
+
limit?: number;
|
|
170
|
+
}): Promise<void>;
|
|
120
171
|
/**
|
|
121
172
|
* Gets the status of a work item.
|
|
122
173
|
*
|
|
@@ -128,6 +179,14 @@ export declare class Workpool {
|
|
|
128
179
|
* - `{ state: "finished" }`
|
|
129
180
|
*/
|
|
130
181
|
status(ctx: RunQueryCtx, id: WorkId): Promise<Status>;
|
|
182
|
+
/**
|
|
183
|
+
* Gets the status of a batch of work items.
|
|
184
|
+
*
|
|
185
|
+
* @param ctx - The query context that can call ctx.runQuery.
|
|
186
|
+
* @param ids - The IDs of the work to get the status of.
|
|
187
|
+
* @returns The status of the work items.
|
|
188
|
+
*/
|
|
189
|
+
statusBatch(ctx: RunQueryCtx, ids: WorkId[]): Promise<Status[]>;
|
|
131
190
|
/**
|
|
132
191
|
* Defines a mutation that will be run after a work item completes.
|
|
133
192
|
* You can pass this to a call to enqueue* like so:
|
|
@@ -255,16 +314,9 @@ export declare function vOnCompleteArgs<V extends Validator<any, "required", any
|
|
|
255
314
|
kind: import("convex/values").VLiteral<"canceled", "required">;
|
|
256
315
|
}, "required", "kind">], "required", "kind" | "returnValue" | `returnValue.${string}` | "error">;
|
|
257
316
|
}, "required", "context" | "workId" | "result" | `context.${V["fieldPaths"]}` | "result.kind" | "result.returnValue" | `result.returnValue.${string}` | "result.error">;
|
|
258
|
-
export type NameOption = {
|
|
259
|
-
/**
|
|
260
|
-
* The name of the function. By default, if you pass in api.foo.bar.baz,
|
|
261
|
-
* it will use "foo/bar:baz" as the name. If you pass in a function handle,
|
|
262
|
-
* it will use the function handle directly.
|
|
263
|
-
*/
|
|
264
|
-
name?: string;
|
|
265
|
-
};
|
|
266
317
|
export type RetryOption = {
|
|
267
318
|
/** Whether to retry the action if it fails.
|
|
319
|
+
* If false, the action won’t be retried.
|
|
268
320
|
* If true, it will use the default retry behavior.
|
|
269
321
|
* If custom behavior is provided, it will retry using that behavior.
|
|
270
322
|
* If unset, it will use the Workpool's configured default.
|
|
@@ -298,22 +350,13 @@ export type WorkpoolRetryOptions = {
|
|
|
298
350
|
*/
|
|
299
351
|
retryActionsByDefault?: boolean;
|
|
300
352
|
};
|
|
301
|
-
export type
|
|
302
|
-
/**
|
|
303
|
-
* The time (ms since epoch) to run the action at.
|
|
304
|
-
* If not provided, the action will be run as soon as possible.
|
|
305
|
-
* Note: this is advisory only. It may run later.
|
|
306
|
-
*/
|
|
307
|
-
runAt?: number;
|
|
308
|
-
} | {
|
|
353
|
+
export type EnqueueOptions = {
|
|
309
354
|
/**
|
|
310
|
-
* The
|
|
311
|
-
*
|
|
312
|
-
*
|
|
355
|
+
* The name of the function. By default, if you pass in api.foo.bar.baz,
|
|
356
|
+
* it will use "foo/bar:baz" as the name. If you pass in a function handle,
|
|
357
|
+
* it will use the function handle directly.
|
|
313
358
|
*/
|
|
314
|
-
|
|
315
|
-
};
|
|
316
|
-
export type CallbackOptions = {
|
|
359
|
+
name?: string;
|
|
317
360
|
/**
|
|
318
361
|
* A mutation to run after the function succeeds, fails, or is canceled.
|
|
319
362
|
* The context type is for your use, feel free to provide a validator for it.
|
|
@@ -343,7 +386,21 @@ export type CallbackOptions = {
|
|
|
343
386
|
* Useful for passing data from the enqueue site to the onComplete site.
|
|
344
387
|
*/
|
|
345
388
|
context?: unknown;
|
|
346
|
-
}
|
|
389
|
+
} & ({
|
|
390
|
+
/**
|
|
391
|
+
* The time (ms since epoch) to run the action at.
|
|
392
|
+
* If not provided, the action will be run as soon as possible.
|
|
393
|
+
* Note: this is advisory only. It may run later.
|
|
394
|
+
*/
|
|
395
|
+
runAt?: number;
|
|
396
|
+
} | {
|
|
397
|
+
/**
|
|
398
|
+
* The number of milliseconds to run the action after.
|
|
399
|
+
* If not provided, the action will be run as soon as possible.
|
|
400
|
+
* Note: this is advisory only. It may run later.
|
|
401
|
+
*/
|
|
402
|
+
runAfter?: number;
|
|
403
|
+
});
|
|
347
404
|
export type OnCompleteArgs = {
|
|
348
405
|
/**
|
|
349
406
|
* The ID of the work that completed.
|
|
@@ -359,4 +416,14 @@ export type OnCompleteArgs = {
|
|
|
359
416
|
*/
|
|
360
417
|
result: RunResult;
|
|
361
418
|
};
|
|
419
|
+
export declare function enqueueBatch<FnType extends FunctionType, Args extends DefaultFunctionArgs, ReturnType>(component: UseApi<Mounts>, ctx: RunMutationCtx, fnType: FnType, fn: FunctionReference<FnType, FunctionVisibility, Args, ReturnType>, fnArgsArray: Array<Args>, options: EnqueueOptions & {
|
|
420
|
+
retryBehavior?: RetryBehavior;
|
|
421
|
+
maxParallelism?: number;
|
|
422
|
+
logLevel?: LogLevel;
|
|
423
|
+
}): Promise<WorkId[]>;
|
|
424
|
+
export declare function enqueue<FnType extends FunctionType, Args extends DefaultFunctionArgs, ReturnType>(component: UseApi<Mounts>, ctx: RunMutationCtx, fnType: FnType, fn: FunctionReference<FnType, FunctionVisibility, Args, ReturnType>, fnArgs: Args, options: EnqueueOptions & {
|
|
425
|
+
retryBehavior?: RetryBehavior;
|
|
426
|
+
maxParallelism?: number;
|
|
427
|
+
logLevel?: LogLevel;
|
|
428
|
+
}): Promise<WorkId>;
|
|
362
429
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EAEnB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EAEnB,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,g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