Increase timeout of saga or cancel timeout and create a new timeout

We are implementing the following saga

  1. As soon as Purchase order is raised by our backoffice, we send an email to the sales office, which needs to approve within 30 mins, if we do not receive a response from the sales office in 30mina, we send a purchase order cancelled event, we have implemented this and its working as expected

the new requirement is during the 30 mins, the sales office can ask for another extra 1hr of time to validate and approve

or cancel the current timeout and create a new timeout of 1 hr.

how can we handle this in a saga ? how can we increase an existing timeout already that is running.

Thanks -Nen

Hi Nen,

This is a fairly common question when using timeouts with sagas.

For your case, you could add another property to your saga data class, let’s say we call it SalesRequestedMoreTime as a boolean. In the handling method of the SalesRequestsMoreTime message, you would set that value to true. Then, in the Timeout method you’ve already got, you’d check that property and if it’s false, do what you’re already doing, and if it’s true, then request a second timeout.

Important: In order to not end up in an endless timeout loop, essentially breaking the original requirement, you’ll need to have some mechanism to detect when you’re going through the timeout the second time. You could reset the SalesRequestedMoreTime property to false, or you could use a different type of parameter for the timeout and create a new timeout method to handle that, just as a couple of examples.

Let me know how that works out for you.

Cheers,
Udi

2 Likes