Tela SDK for JavaScript
    Preparing search index...

    Class BatchExecution<TOutput>

    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.

    The batch status can be accessed via the status property and tracks the lifecycle:

    • Batch executions: createdvalidatingrunningcompleted or failed
    • Can be canceled: At any time before completion using cancel()

    Status is set to failed when:

    • Input file validation fails
    • Batch processing encounters an error
    • Server reports failure status

    Status is set to completed when:

    • All executions in the batch finish processing
    • Output file is generated and available

    Events are emitted during polling to track progress:

    • statusChange - Status transitions (created → validating → running → completed)
    • poll - Each polling attempt with current progress
    • success - Completion with the BatchExecutionResult
    • error - Failure notification

    Important: Events are only emitted while polling is active. You must either call poll() or await execution.result to start polling.

    poll - Emitted during polling with current status and progress. Includes requestId from the polling request.

    success - Emitted when batch completes successfully with the result object. Includes requestId from the final request.

    error - Emitted when batch fails (only if error listeners are registered, otherwise throws)

    statusChange - Emitted when batch status transitions to a new state

    const execution = await batch.execute()

    // Track progress with events
    execution.on('statusChange', ([status, response]) => {
    console.log(`Status: ${status}`)
    if (response.state) {
    console.log(`Progress: ${response.state.completed}/${response.state.total}`)
    }
    })

    execution.on('success', (result) => {
    console.log('Batch completed!')
    console.log('Request ID:', result.requestId)
    })

    // Start polling without waiting
    execution.poll()

    Type Parameters

    • TOutput

      The output result type for individual executions

    Hierarchy

    Index

    Constructors

    Accessors

    Methods

    Constructors

    • Internal

      Creates a new batch execution instance.

      Type Parameters

      • TOutput

      Parameters

      • id: string

        Unique identifier for this batch execution.

      • client: BaseClient

        HTTP client for making API requests.

      • params: BatchParams = {}

        Batch execution parameters.

      • creationResponse: WithRequestId<BatchResponse>

        Initial response from batch creation.

      Returns BatchExecution<TOutput>

    Accessors

    • get id(): string

      Gets the unique identifier for this batch execution.

      Returns string

      The batch execution ID.

    • get result(): Promise<BatchExecutionResult<TOutput>>

      Gets the batch execution result. Automatically starts polling if not already started.

      Returns Promise<BatchExecutionResult<TOutput>>

      A promise resolving to the batch execution result.

      const execution = await batch.execute()
      const result = await execution.result

      // Access results
      const outputs = await result.getResults()
      console.log(`Got ${outputs.length} results`)
    • get status(): BatchExecutionStatus

      Gets the latest known status of the batch execution.

      Status values and transitions:

      • createdvalidatingrunningcompleted or failed
      • Can transition to canceled from any non-terminal state

      Use the statusChange event to track status transitions in real-time.

      Returns BatchExecutionStatus

      The current status of the batch execution.

      const execution = await batch.execute()
      console.log(execution.status) // 'created'

      execution.on('statusChange', ([status]) => {
      console.log('New status:', status)
      })

      await execution.result
      console.log(execution.status) // 'completed' or 'failed'

    Methods

    • 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.

      Returns Promise<void>

      A promise that resolves when the cancellation request completes.

      const execution = await batch.execute()
      execution.poll()

      // Cancel after some condition
      if (shouldCancel) {
      await execution.cancel()
      console.log(execution.status) // 'canceled'
      }
    • 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 response
      • success: Emitted when the batch completes successfully with the final result
      • error: Emitted if the batch fails

      Important: 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.

      Returns void

      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()