Introduction
Are you facing an issue where WorkflowExecutionInfo.memo
is empty even after successfully calling upsertMemo
in your TypeScript application? This can be frustrating, especially after seeing the memo correctly set in your workflow execution output. Let’s dive into why this issue might occur and how to address it effectively.
Understanding the Issue
The main problem stems from the timing and lifecycle of updating the memo in your workflow executions. When you call the upsertMemo
method, it is crucial to ensure that the memo is set correctly and acknowledged before you attempt to retrieve it from the workflow executions.
In your code, the memo appears to be set successfully, as confirmed by the output of console.log
. However, the memo is not persisted as expected when viewed through TemporalClient.workflowService.listWorkflowExecutions
. Let’s explore the possible reasons why this happens:
Potential Reasons for Empty Memo
-
Memo Not Persisted: The memo might not be properly persisted due to timing issues in the workflow execution. If
upsertMemo
is called asynchronously, there might be a race condition where the memo is not saved before querying it. - Workflow Execution Status: Check the status of your workflow execution. If the workflow has already completed, any changes to the memo may not be reflected. Memos can only be stored while a workflow is running.
- Namespace Mismatch: Make sure that you are querying the workflow executions from the correct namespace. If there’s a mismatch, you may not be fetching the intended workflow execution.
- Memo Size Limit: Be aware that Temporal has a size limit for memos. Ensure your memo does not exceed the maximum allowed size.
Step-by-Step Solution
To resolve this issue, follow these coding strategies to ensure that memos are stored and retrieved correctly.
Step 1: Confirm Memo Update Flow
Ensure that the upsertMemo
method is called within the appropriate workflow context and that you are waiting for it to complete.
async function myWorkflow() {
const fieldValue = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
await upsertMemo({'fieldName': fieldValue});
console.log(`Memo set to ${JSON.stringify(workflowInfo().memo)}`);
}
Step 2: Await Workflow Execution Completion
Make sure that you are waiting for the workflow to complete before you list the workflow executions. You can use the await
keyword alongside Temporal's APIs:
const result = await client.execute(myWorkflow, { taskQueue: 'my-task-queue' });
Step 3: Query Workflow Execution
When using listWorkflowExecutions
, ensure you have the correct query and wait for the executions to be available:
const client: Client = await this.temporalService.getClient();
const workflowExecutions = await client.workflowService.listWorkflowExecutions({
query: "WorkflowType = 'workflowName'",
namespace: 'default',
});
for await (const execution of workflowExecutions.executions) {
console.log(`Found workflow ${execution.execution?.workflowId}`);
const memo = execution.memo;
console.log(`Memo = ${JSON.stringify(memo)} (${memo})`);
}
Step 4: Check Overall Workflow Health
It's also important to check the overall health of your workflow execution. Look for any errors or logs that provide insight into the state of your workflows.
Frequently Asked Questions
1. What should I do if the workflow completes, and I still don’t see the memo?
If the workflow has completed, it’s essential to revisit your logic. Ensure that the memo is set before the workflow finishes. Consider setting a temporary value to check whether the memo retrieves correctly.
2. Are there limits on the size of memos?
Yes, Temporal enforces a size limit on the data you can store in memos. Check if your memo exceeds that limit.
3. Can I access memo data retrospectively?
No, memo data cannot be accessed retrospectively once a workflow has completed. Ensure memos are set during the execution phase.
4. What if I still can’t retrieve the memo?
Check if your memo serialization is handled properly and verify the Temporal SDK you are using. You may also want to inspect generated Temporal logs for anomalies.
Conclusion
When dealing with Temporal workflows and memos, timing and context matter significantly. Always ensure memos are updated and queried within the correct operational scope. Following the steps outlined in this article should help you troubleshoot and solve the issue of the empty memo in your TypeScript application.