Is It Allowed to Use Temporal Client in Activities for Workflow Status Check?

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:

  1. Parent Workflow:
  • Starts a child workflow with WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING.
  • Needs to periodically check if the child workflow is canceled.
  1. 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:

  1. 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!

If a child is canceled, the Future that was returned from ExecuteChildWorkflow will be resolved. So there is no need to poll for status.