How to structure a workflow so it ends

I have a workflow that needs to send a series of text & email messages.

Once the workflow begins theres about 15 seconds to accomplish the activities (one for a text and one for an email).

However if there is a failure to finish within those 15 seconds to send a third email with a different activity (only on the failure).

So i’ve done just that and created an activity with a startToFinish of 15 seconds - but that’s not exactly what i wanted for the context deadline to exceed.

Additionally i noticed new tasks get queued and sometimes all get stuck in a ‘running’ state.Each task has a unique workflow id but the same task queue id.

How can I make it so all new workflows run concurrently and don’t wait for the old one to finish (i’m not sure if this is the exact behaviour thats going on it might be concurrent but its just hard to tell when everything on the temporal-web ui is ‘Running’ but it seems like nothing is happening). And also how can i have a failure activity that runs if the first 2 activities aren’t run in time.

Thanks for helping me

Which SDK are you using?

How can I make it so all new workflows run concurrently and don’t wait for the old one to finish

Workflows are executed concurrently. Can you show your client code that’s starting workflows?

hard to tell when everything on the temporal-web ui is ‘Running’ but it seems like nothing is happening

One thing to look into is the workflow event history. Could you show for one of your running workflows?

And also how can i have a failure activity that runs if the first 2 activities aren’t run in time.

One way you could do it is to have the first two activities in a child workflow that has a defined execution timeout. If it times out, you can catch the exception and perform the 3rd activity. Another way would be to start the first two activities async and wait for their result up to a certain timeout.
What do you have currently so we can take a look at help you.

  1. Im using the Go sdk + Typescript sdk + Call directly via grpc

  2. All my code is performing this way for over 20 workflows thats why I have created the question more generically

An example of a workflow with the issue is

	ao := workflow.ActivityOptions{
		StartToCloseTimeout: 10 * time.Second,
	}
	ctx = workflow.WithActivityOptions(ctx, ao)

	logger := workflow.GetLogger(ctx)

	//Check it can be done first
	err := workflow.ExecuteActivity(ctx, transfer.Check, wf).Get(ctx, nil)

	if err != nil {
		logger.Info("Activity", "Unable to execute query")
		return err
	}


	//Transfer completion
	err = workflow.ExecuteActivity(ctx, transfer.CompleteTransfer, wf).Get(ctx, nil)
	if err != nil {
		logger.Info("Activity", "Unable to execute query")
		return err
	}
  1. A running workflow

I’m really confused about how the start to close timeout is 10 seconds but my workflow is sitting as ‘Running’ a day later. I then have to manually terminate it. The activity as part of the workflow is still ‘Scheduled’ because it failed, which makes sense but then the workflow is over at some point. So the first activity ‘Check’ fails and it just stays running forever.

How can I catch a timeout and do a third activity? Is there an example of that?

StartToCloseTimeout is the maximum time for a single activity execution.
Note that by default activities are retried. You can set the ScheduleToCloseTimeout, which includes also the time for all activity retries.
Check out this video that explains all activity timeouts.

Note that if you don’t set ScheduleToCloseTimeout, your activities will retry up to the workflows WorkflowOptions->WorkflowExecutionTimeout. If this is not set, the default WorkflowExecutionTimeout is “unlimited”, so that’s probably why in your sample the workflow keeps running, waiting for a fix for the activity failure (and keeps retrying).