Monitor Workflow
When the workflow is running, it will generate events in the database. These events can be used to monitor the state of the workflow.
Workflow Events
Belows are the events that will be generated by the workflow with their description.
Event | Description | Attributes |
---|---|---|
WorkflowExecutionStarted | always the first event in a workflow execution event history | input |
WorkflowExecutionCompleted | indicates that the workflow execution has successfully completed | result |
WorkflowExecutionFailed | indicates that the workflow execution has unsuccessfully completed with error | failure |
WorkflowExecutionCanceled | indicates that the workflow execution has been canceled | details |
WorkflowExecutionTerminated | indicates that the workflow execution has been terminated | reason |
ActivityTaskScheduled | indicates that the activity task has been scheduled | input |
ActivityTaskStarted | indicates that the activity task has started | last_failure |
ActivityTaskCompleted | indicates that the activity task has completed | result |
ActivityTaskCancelRequested | indicates that a request has been made to cancel the activity task | |
ActivityTaskCanceled | indicates that the activity task has been canceled | |
ActivityTaskFailed | indicates that the activity task has failed | failure |
FormTaskScheduled | indicates that the form task has been scheduled | input |
FormTaskStarted | indicates that the form task has started | workflow_id, workflow_run_id |
FormTaskCompleted | indicates that the form task has completed | result |
FormTaskFailed | indicates that the form task has failed | failure |
RecoverTaskScheduled | indicates that the recover task has been scheduled | input |
RecoverTaskStarted | indicates that the recover task has started | workflow_id, workflow_run_id |
RecoverTaskCompleted | indicates that the recover task has completed | result |
RecoverTaskFailed | indicates that the recover task has failed | failure |
CallActivityTaskScheduled | indicates that the callActivity task has been scheduled | input |
CallActivityTaskStarted | indicates that the callActivity task has started | workflow_id, workflow_run_id |
CallActivityTaskCompleted | indicates that the callActivity task has completed | result |
CallActivityTaskFailed | indicates that the callActivity task has failed | failure |
Tracking Workflow Execution History
To track the workflow execution history, make a GET
HTTP request to {WFM_URL}/v1/workflow/{workflow_id}
which returns the history of the workflow execution states up to the current state.
Example API response
{
"data": [
{
"event_type": "WorkflowExecutionStarted",
"timestamp": "2024-10-24T10:47:35.14814Z",
"attributes": {
"input": [
{
"States": []
}
]
}
},
{
"event_type": "ActivityTaskScheduled",
"timestamp": "2024-10-24T10:47:35.160881Z",
"task_name": "example",
"task_type": "ExampleActivity",
"attributes": {
"input": [
"Hello"
]
}
},
{
"event_type": "ActivityTaskStarted",
"timestamp": "2024-10-24T10:47:35.165684Z",
"task_name": "example",
"task_type": "ExampleActivity"
},
{
"event_type": "ActivityTaskCompleted",
"timestamp": "2024-10-24T10:47:35.166853Z",
"task_name": "example",
"task_type": "ExampleActivity",
"attributes": {
"result": [
"Hello"
]
}
},
{
"event_type": "WorkflowExecutionCompleted",
"timestamp": "2024-10-24T10:53:02.343729Z",
"attributes": {
"result": [
{
"example_input": "Hello",
"Result_example": "Hello"
}
]
}
}
],
"sent_at": "2024-10-30T09:37:27Z",
"page": {
"number": 1,
"size": 5,
"total_records": 5,
"count": 5,
"sort": [
""
]
}
}
The API is paginated, so you can get the history of the workflow execution states by specifying the page number and page size as well as you can sort the timestamp in ascending or descending order.
For example, if you want to get the last event of the workflow execution history, you can specify the path parameter
with {WFM_URL}/v1/workflow/{workflow_id}?page=1&size=1&sort=timestamp,desc
.
Example API response
{
"data": [
{
"event_type": "WorkflowExecutionCompleted",
"timestamp": "2024-10-24T10:53:02.343729Z",
"attributes": {
"result": [
{
"example_input": "Hello",
"Result_example": "Hello"
}
]
}
}
],
"sent_at": "2024-10-30T09:37:27Z",
"page": {
"number": 1,
"size": 1,
"total_records": 5,
"count": 1,
"sort": [
"timestamp desc"
]
}
}
Based on the event type in the response, you can create the corresponding event handler user interface.