forked from triggerdotdev/trigger.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch.ts
More file actions
70 lines (66 loc) · 1.77 KB
/
batch.ts
File metadata and controls
70 lines (66 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {
accessoryAttributes,
apiClientManager,
ApiPromise,
ApiRequestOptions,
mergeRequestOptions,
RetrieveBatchResponse,
} from "@trigger.dev/core/v3";
import {
batchTriggerById,
batchTriggerByIdAndWait,
batchTriggerTasks,
batchTriggerAndWaitTasks,
} from "./shared.js";
import { tracer } from "./tracer.js";
export const batch = {
trigger: batchTriggerById,
triggerAndWait: batchTriggerByIdAndWait,
triggerByTask: batchTriggerTasks,
triggerByTaskAndWait: batchTriggerAndWaitTasks,
retrieve: retrieveBatch,
};
/**
* Retrieves details about a specific batch by its ID.
*
* @param {string} batchId - The unique identifier of the batch to retrieve
* @param {ApiRequestOptions} [requestOptions] - Optional API request configuration options
* @returns {ApiPromise<RetrieveBatchResponse>} A promise that resolves with the batch details
*
* @example
* // First trigger a batch
* const response = await batch.trigger([
* { id: "simple-task", payload: { message: "Hello, World!" } }
* ]);
*
* // Then retrieve the batch details
* const batchDetails = await batch.retrieve(response.batchId);
* console.log("batch", batchDetails);
*/
function retrieveBatch(
batchId: string,
requestOptions?: ApiRequestOptions
): ApiPromise<RetrieveBatchResponse> {
const apiClient = apiClientManager.clientOrThrow();
const $requestOptions = mergeRequestOptions(
{
tracer,
name: "batch.retrieve()",
icon: "batch",
attributes: {
batchId: batchId,
...accessoryAttributes({
items: [
{
text: batchId,
variant: "normal",
},
],
style: "codepath",
}),
},
},
requestOptions
);
return apiClient.retrieveBatch(batchId, $requestOptions);
}