Interact Temporal Workflow from User Interface

Hi,

I am trying to implement Interaction from UI to retry in case of failure in a particular activity in the temporal workflow.

I am trying to use signal and continue as a new capability to enable this feature. Could anyone confirm this is the right approach?

I am currently facing an error with continuing as new. Below is the sample test code snippet.

const { activity1, activity2 } = proxyActivities<typeof activities>({
  startToCloseTimeout: '5 minute',
  retry: {
    // default retry policy if not specified
    initialInterval: '20s',
    backoffCoefficient: 1,
    maximumAttempts: 1,
    maximumInterval: 100 * 1000,
    nonRetryableErrorTypes: [],
  }
});

export const userDecisionSignal = defineSignal<[string]>('userDecision');

export async function taskApprovalWorkflow(payload: any): Promise<string> {
  let userDecision = 'waiting'
  wf.setHandler(userDecisionSignal, (action) => {
    userDecision = action;
  })
  try{
    await activity1(payload);
    await activity2(payload);
  }catch(error){
     if (await condition(() => (userDecision === 'retry'), '3600s')) {
      const continueAsNewOptions = {
        workflowType: "taskApprovalWorkflow",
        input: {
          "queryParams": {
            "workflowName": "test123",
            "subWorkflowName": "test",
            "capabilityName": "xyz",
            "requestType": "sync"
          },
          "body": {
            "xyz": "xyz"
          },
        "workflowId":  payload.workflowId
      },
        workflowId: payload.workflowId 
      };
      wf.continueAsNew(continueAsNewOptions);
     }
  }

}

I am throwing exceptions in activity1 intentionally to make the workflow wait till I get a signal from the UI. Once I get a signal wf.continueAsNew gets called, but on call of activity 1 throws an exception, it is not even going inside the activity.

Below is the error I see in workflow

  "stackTrace": "ContinueAsNew: Workflow continued as new\n    at /Users

You need to await continue as new, it returns a rejected promise. In your example you’re seeing an unhandled promise rejection failing the workflow task