The output result type for individual executions
InternalCreates a new batch execution instance.
Unique identifier for this batch execution.
HTTP client for making API requests.
Batch execution parameters.
Initial response from batch creation.
Gets the unique identifier for this batch execution.
The batch execution ID.
Gets the batch execution result. Automatically starts polling if not already started.
A promise resolving to the batch execution result.
Gets the latest known status of the batch execution.
Status values and transitions:
created → validating → running → completed or failedcanceled from any non-terminal stateUse the statusChange event to track status transitions in real-time.
The current status of the batch execution.
Cancels the batch execution.
Sends a cancellation request to the server and aborts any ongoing polling. The batch will stop processing, but already-completed executions remain available.
A promise that resolves when the cancellation request completes.
Starts polling for the batch result without waiting for the promise to resolve. This allows users to track batch progress via events rather than awaiting a promise.
The following events will be emitted during polling:
statusChange: Emitted when the batch status changes (e.g., 'created' → 'running' → 'completed')poll: Emitted on each polling attempt with the server responsesuccess: Emitted when the batch completes successfully with the final resulterror: Emitted if the batch failsImportant: Events are only emitted while polling is active. You must call poll() or
await execution.result to start polling. Simply setting up event listeners without starting
polling will not trigger any events.
const execution = await batch.execute()
// Set up event listeners
execution.on('statusChange', ([status, response]) => {
console.log(`Status: ${status}`)
if (response.state) {
const { completed, total } = response.state
console.log(`Progress: ${completed}/${total}`)
}
})
execution.on('success', (result) => {
console.log('Batch completed!')
console.log('Request ID:', result.requestId)
})
execution.on('error', (error) => {
console.error('Batch failed:', error)
})
// Start polling without waiting
execution.poll()
Manages the execution lifecycle of a batch operation.
Handles polling for batch completion, progress tracking, and result retrieval. Provides an event-driven API for monitoring batch progress in real-time.
Status Tracking
The batch status can be accessed via the
statusproperty and tracks the lifecycle:created→validating→running→completedorfailedcancel()Status is set to
failedwhen:Status is set to
completedwhen:Event System
Events are emitted during polling to track progress:
statusChange- Status transitions (created → validating → running → completed)poll- Each polling attempt with current progresssuccess- Completion with the BatchExecutionResulterror- Failure notificationImportant: Events are only emitted while polling is active. You must either call
poll()or awaitexecution.resultto start polling.Fires
poll - Emitted during polling with current status and progress. Includes
requestIdfrom the polling request.Fires
success - Emitted when batch completes successfully with the result object. Includes
requestIdfrom the final request.Fires
error - Emitted when batch fails (only if error listeners are registered, otherwise throws)
Fires
statusChange - Emitted when batch status transitions to a new state
Example