Need to voluntarily fail workflow activities?

Hi Team, @maxim @tihomir

I have a workflow which uses asynchronous temporal activities. I need to explicitly fail all the activities at any point when a signal is received from external world.

Will I be able to close all the current activity in java ?

Thanks
Vishal

You cannot fail them, but you can cancel them from the workflow. Then, you can either wait for them to confirm the cancellation or proceed without waiting.

1 Like

Thanks @maxim. I try to cancel the activity by following @tihomir’s demo → temporal-cancel-activity/src/main/java/io/temporaldemo/TemporalWorkflow.java at main · tsurdilo/temporal-cancel-activity · GitHub.

Instead of having the scope cancelled by a signal, I am having a separate internal thread with a timer which will invoke the scope’s cancel method.

Immediately after the internal thread completes the timer and cancels the scope, there is an exception and the cause is CanceledFailure, the code flows through the exception handlers and stops before calling the next activity while my main thread is still doing the work which was triggered by the activity.

Even after the activity has been cancelled I could see the output of the cancelled activity in the UI after it completes.

and for some reason I am not able to run the next activity and the whole workflow fails.

Please find the error log.

io.temporal.client.WorkflowFailedException: Workflow execution {workflowId='f90654d4-5da6-44cf-9a3a-ef976b721f6c', runId='c47d24c8-4421-43f2-87b9-be0f91067bda', workflowType='ITemporalWorkflow'} failed. Metadata: {closeEventType='EVENT_TYPE_WORKFLOW_EXECUTION_FAILED', retryState='RETRY_STATE_RETRY_POLICY_NOT_SET', workflowTaskCompletedEventId=20'}

Caused by: io.temporal.failure.ApplicationFailure: message='Failure handling event 15 of type 'EVENT_TYPE_ACTIVITY_TASK_SCHEDULED' during replay. Event 15 of type EVENT_TYPE_ACTIVITY_TASK_SCHEDULED does not match command type COMMAND_TYPE_RECORD_MARKER. {WorkflowTaskStartedEventId=19, CurrentStartedEventId=11}', type='io.temporal.worker.NonDeterministicException', nonRetryable=false

Also saw this post → cancel local activity

Below are my questions.

  1. May I know why my workflow is getting replayed ?
  2. Should I only cancel an activity from a signal ?
  3. What will happen to the main thread which is executing a synchronous activity when the activity is cancelled by another thread ?
  4. Is there a way I can cancel my local activity now ?

Thanks for the help in advance :+1: