Over 10 years we help companies reach their financial and branding goals. Engitech is a values-driven technology agency dedicated.

Gallery

Contacts

411 University St, Seattle, USA

engitech@oceanthemes.net

+1 -800-456-478-23

How to “continueAsNew” a child workflow in Temporal (TypeScript SDK)?

Before knowing how to ContinueAsNew in temporal, let’s get to know what exactly Temporal is and what is the role of workflows in it. 

Temporal

It is a developer-first and open-source platform which makes sure of the execution of services and applications. (using workflows). Temporal has made easier the management of long-running workflows. It is quite simple to start the installation with temporal. Anyone can get started by using their own workflows. 

You can write reliable and highly scalable long-running workflows with temporal Typescript SDK without having expertise in distributed systems. Although it has been designed with the experience of the first developer, it works fine with JavaScript. 

Workflows

Here summarise the orchestration of tasks that include child Workflow and Activities. Temporal provides a scheduling facility. You can schedule a cron for your workflow execution. It provides a user-friendly and flexible approach to users. 

Prerequisites of using Temporal

Here is a description of the things required for using temporal. 

  • You need to have Node.js 14 plus: this project requires  14 or later versions of Node.js 
  • You will also be needing a Temporal Server to run this: make sure it runs locally!
    • Run Temporal Server ( it requires Docker and Docker Compose):
    • Commands to run Temporal server on desktop;  

git clone https://github.com/temporalio/docker-compose.git temporal
cd temporal
docker-compose up

I assume you have already created an application using Typescript SDK, and inside your parentWorkflow you have spawned a childWorkflow, and you want it to ContinueAsNew after a specific interval. Moving forward, let’s know what does ContinueAsNew means and how it works.

How to “Continue-As-New”?

“Continue-As-New” is a mechanism that helps start a new workflow execution with a brand new event history when the latest relevant state is passed to a new Workflow Execution. 

The Temporal Platform will alert you every 10,000 Events or 10 MB and restrict the total Event History to 50,000 Events or 50 MB as a precaution. Here, you will have to use Continue-As-New to start a new Workflow Execution with a new Event History in order to avoid the “Workflow Execution Event History” going over this limit and failing.

If the number of Events in the Event History is growing too large, Continue-As-New allows a Workflow Execution to successfully close and create a new Workflow Execution in a single atomic operation. The Continue-As-New Workflow Execution has the same Workflow Id, a new Run Id, and a brand-new Event History, and all the necessary parameters are passed.

What happens when you ContinueAsNew?

The response of continue-As-New is always rejected. It never resolves.

continueAsNew

Don’t know what that means? 

Don’t worry! I have a solution for you.

Solution:

ContinueAsNew is implemented by throwing a special exception, you should let that exception propagate.

Explanation:

You just need not worry about the error. Because every time you continueAsNew, it throws an error even if you succeed. You have to just catch and throw that error so it can propagate. It will solve your problem. The only challenge you have to face is to figure out which was the actual success and rejection because it throws errors on both the success and rejection states. You have to identify the rejection state to throw that error to propagate. 

I hope this guide will help you resolve your error while ContinueAsNew. 

Don’t forget to comment if you find it helpful.

Leave a comment

Your email address will not be published.

Recent Posts

Subscribe to get notifications for Latest Blogs

Skip to content