The input variables type
The output result type
OptionalrequestId: stringOptionaloutputSchema: Gets the unique task ID assigned by the server.
The task ID.
Gets the task label (alias for name).
The task name.
Gets the task name.
The task name.
Gets the request ID from the x-request-id header of the task creation request.
This is the request ID from the initial POST /task request that created the task. Each API request has its own unique request ID.
For polling operations, different request IDs are available:
task.requestId - ID from the task creation requestpollResult.requestId - ID from each polling request (in poll events)result.requestId - ID from the final successful polling request (in success events)A promise that resolves to the request ID from the task creation request.
Gets the task result. Automatically starts polling if not already started.
A promise that resolves to the validated task output.
Gets the latest known status of the task.
Status values and transitions:
created → running → completed or failedImportant: Status is set to completed only after successful validation.
If validation fails, status will be failed even if the API request succeeded.
Use the statusChange event to track status transitions in real-time.
The current status of the task.
Gets the task tags.
The task tags.
Starts polling for the task result without waiting for the promise to resolve. This allows users to track task progress via events rather than awaiting a promise.
The following events will be emitted during polling:
statusChange: Emitted when the task status changes (e.g., 'created' → 'running' → 'completed')poll: Emitted on each polling attempt with the server responsesuccess: Emitted when the task completes successfully with the final resulterror: Emitted if the task failsImportant: Events are only emitted while polling is active. You must call poll() or
await task.result to start polling. Simply setting up event listeners without starting
polling will not trigger any events.
const task = await workstation.createTask({ query: 'test' })
// Set up event listeners
task.on('statusChange', (status) => {
console.log('Status:', status)
})
task.on('success', (result) => {
console.log('Completed:', result)
})
task.on('error', (error) => {
console.error('Failed:', error)
})
// Start polling without waiting
task.poll()
Represents a workstation task with event-driven status tracking and result polling.
Tasks are always asynchronous and require polling to retrieve results. The Task class provides an event system for monitoring task lifecycle and automatic output validation.
Status Tracking
Task status can be accessed via the
statusproperty and tracks the lifecycle:created→running→completedorfailedStatus is set to
failedwhen:Status is set to
completedonly after:Fires
poll - Emitted during polling with current status and output. Includes
requestIdfrom the polling request.Fires
success - Emitted when task completes successfully with the final result. Includes
requestIdfrom the final request.Fires
error - Emitted when task fails (only if error listeners are registered, otherwise throws)
Fires
statusChange - Emitted when task status transitions to a new state
Example