Hi Temporal Community,
I need to periodically check if a child workflow has been canceled from within a parent workflow. However, I came across the following note in the documentation:
// Package client is used by external programs to communicate with Temporal service.
//
// NOTE: DO NOT USE THIS API INSIDE OF ANY WORKFLOW CODE!!!
package client
Given this constraint, what is the best practice for periodically checking the status of a child workflow?
Current Setup:
- Parent Workflow:
- Starts a child workflow with
WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING
. - Needs to periodically check if the child workflow is canceled.
- Activity for Checking Status: Defined an activity to get the status of a workflow:
package activities
import (
"context"
"go.temporal.io/sdk/client"
)
type Activities struct {
TemporalClient client.Client
}
func (a *Activities) GetWorkflowStatus(ctx context.Context, workflowID, runID string) (string, error) {
descResp, err := a.TemporalClient.DescribeWorkflowExecution(ctx, workflowID, runID)
if err != nil {
return "", err
}
return descResp.WorkflowExecutionInfo.Status.String(), nil
}
Questions:
- Is using an activity to check the workflow status using activity is the right approach? or is it forbidden as stated inside the client package
Thanks in advance for your help!