Terminate workflows with an API call

@maxim what would be the best approach to terminate a workflow execution from the workflow itself depending on the response from an activity?

Is it ok to implement something similar to your code in the workflow method? should we use a local activity instead??

Thanks in advance.

PS: Just to clarify, I know that if we return from the method it will finish the execution, but the thing is that by finishing the workflow in that way, when you check in temporal web the workflow will appear as completed. I would like it to appear as ‘Failed’.

Nevermind, I found the answer I was looking for in here:

Regards.

@ryland @maxim
i have a namespace → n
In that namespace
Let say i have a workflow->w1, in queue q1
Let say i have a workflow->w2, in queue q2
Can i teminate workflow w2 from workflow w1, if i have workflowID?

Yes, you can, but you have to do it from an activity as termination is not supported from workflow to workflow directly.

1 Like

Can i teminate workflow w2 from workflow w1, if i have workflowID?

Whats the use case for termination vs canceling w2 (so you could for example do some cleanup)

i have distributed architecture.
for each service, handles some resource, for each resource i am running workflow in a queue
I have named queues based on service name.
So resource 1 of servuce A resource 2 of service B are linked through FK key. If i want to terminate workflow of resource 1 , i also want to terminate all related workflows

so from activity → a1 of workflow → w1
i can cancel workflow → w2 right?

Yes you can terminate or cancel using client apis.

1 Like

Hello there, Im working with the Golang SDK attempting to terminate a workflow. In code we don’t actually care if there was a running workflow running already, we call Terminate() as part of deleting a tenant from a system. Per the lib annotations the method may return a couple of serviceerror errors. How do we check for those errors? I want to ignore NotFound instances. The following code does not work:

	err := s.temporalClient.TerminateWorkflow(ctx, domain.BuildTenantAutorenewalWorkflowID(tenantID), "", "tenant deletion request")
	if !errors.Is(err, &serviceerror.NotFound{}) && !errors.Is(err, sql.ErrNoRows) {
		// if not found, nothing to delet, otherwise bubble up
		s.l.Error("DeleteTenant: failed to delete autorenewal tenant workflow", zap.String("TenantID", tenantID.String()), zap.Error(err))
		return fmt.Errorf("failed to delete autorenewal tenant workflow: %w", err)
	}

And the actual error is literally sql.ErrNoRows
My log entry:

2023-10-31T01:14:22Z	ERROR	service/cert-monitor.go:372	DeleteTenant: failed to delete autorenewal tenant workflow	{"TenantID": "9bcabd90-7748-11ee-a4bb-290f18bcdfca", "error": "sql: no rows in result set"}

Will appreciate some guidance, cheers