Skip to main content

Workflow Progress

During workflow execution, you can provide real-time progress information to the client application. The framework supports three distinct types of progress updates to keep clients informed about the task execution status:

Progress Metrics

Currently available via Async API

Progress metrics allow you to report completion percentage and estimated remaining time for a task. This is particularly useful for long-running operations where clients need to track overall progress.


@Executor("example-task")
export class ExampleExecutor implements TaskExecutor {
async processTask(command: any, metadata: TaskMetadata, flow: Flow): Promise<ExampleResponse> {
await flow.emitProgresMetrics({
percent: 27, // progress percentage (0 to 100)
estimatedSecondsLeft: 14, // optional remaining time in seconds
});
sleep(5000);
return {
name: 'Joe',
surname: `Doe`
}
}
}

For tasks with predictable durations, you can automatically schedule progress updates based on the average execution time:


@Executor("example-task")
export class ExampleExecutor implements TaskExecutor {
async processTask(command: any, metadata: TaskMetadata, flow: Flow): Promise<ExampleResponse> {
await flow.scheduleProgressMetrics(60_000);
sleep(5000);
return {
name: 'Joe',
surname: `Doe`
}
}
}

Partial Result

Currently available via Async API

Partial results enable you to send intermediate results to the client during task execution. These results should be a subset of your final result schema, allowing clients to start processing data before the task completes.

Important: Only the most recently emitted partial result is accessible to clients during polling.


@Executor("example-task")
export class ExampleExecutor implements TaskExecutor {
async processTask(command: any, metadata: TaskMetadata, flow: Flow): Promise<ExampleResponse> {
await flow.emitPartialResult({
name: 'Joe'
});
sleep(5000);
return {
name: 'Joe',
surname: `Doe`
}
}
}

Events

Currently available via Stream API

Events provide a way to send structured updates about specific occurrences during workflow execution. Unlike partial results, events are streamed to the client and can be used to communicate various execution milestones or state changes.


@Executor("example-task")
export class ExampleExecutor implements TaskExecutor {
async processTask(command: any, metadata: TaskMetadata, flow: Flow): Promise<ExampleResponse> {
await flow.emitEvent({
type: 'name.generated',
data: {
name: 'Joe'
}
});
sleep(5000);
return {
name: 'Joe',
surname: `Doe`
}
}
}