Track the status of async operations like collection creation, token minting, and contract deployment.
Methods
getWorkflowStatus()
Get the status and result of an async workflow.
Signature:
getWorkflowStatus(
workflowId: string,
requestOptions?: RequestOptions
): Promise<WorkflowStatusData>
Parameters:
| Parameter | Type | Required | Description |
|---|
workflowId | string | Yes | Workflow ID |
Example:
const status = await client.workflows.getWorkflowStatus('workflow-id');
console.log('Status:', status.data.status);
console.log('Result:', status.data.result);
if (status.data.status === 'COMPLETED') {
console.log('Workflow completed successfully!');
console.log('Result:', status.data.result);
} else if (status.data.status === 'FAILED') {
console.error('Workflow failed:', status.data.error);
}
Response:
{
data: {
status: 'RUNNING' | 'COMPLETED' | 'FAILED' | 'TERMINATED',
result?: any,
error?: string
}
}
Workflow Status Values
- RUNNING: Operation is in progress
- COMPLETED: Operation completed successfully
- FAILED: Operation failed (check error details)
- TERMINATED: Operation was terminated
Complete Example
import { OumlaSdkApiClient, OumlaSdkApiEnvironment } from '@oumla/sdk';
const client = new OumlaSdkApiClient({
environment: OumlaSdkApiEnvironment.Sandbox,
apiKey: 'your-api-key'
});
async function waitForWorkflow(workflowId: string) {
let status;
let attempts = 0;
const maxAttempts = 60; // 2 minutes max (60 * 2 seconds)
do {
status = await client.workflows.getWorkflowStatus(workflowId);
console.log(`Attempt ${attempts + 1}: Status = ${status.data.status}`);
if (status.data.status === 'COMPLETED') {
console.log('Workflow completed!', status.data.result);
return status.data.result;
}
if (status.data.status === 'FAILED') {
throw new Error(`Workflow failed: ${status.data.error}`);
}
if (status.data.status === 'TERMINATED') {
throw new Error('Workflow was terminated');
}
// Wait 2 seconds before checking again
await new Promise(resolve => setTimeout(resolve, 2000));
attempts++;
} while (attempts < maxAttempts && status.data.status === 'RUNNING');
if (status.data.status === 'RUNNING') {
throw new Error('Workflow timeout - still running after max attempts');
}
return status.data.result;
}
// Usage
try {
const result = await waitForWorkflow('workflow-id');
console.log('Final result:', result);
} catch (error) {
console.error('Error waiting for workflow:', error);
}
Polling Strategy: Implement exponential backoff for production applications to avoid excessive API calls while waiting for workflows to complete.