CroaToa
CroaToa

Reputation: 910

AWS: a Workflow with Step Functions with retries and timeout

I'm trying to implement a basic workflow (basic in my opinion), but I cannot figure out the AWS step functions way.

Basically, the requirements are the following:

  1. Run a function that will send an email to a user with a special link
  2. If the user doesn't click the link after 2 days - send a reminder
  3. If the user doesn't click the link after another 3 days - send another reminder.
  4. If the user clicks the link then proceed to another step.
  5. If the user doesn't click the link within 2 months from the initial email - fail the entire workflow.

So based on the requirements above I'm trying to combine that 2 months "timeout" and reminder mechanism, but it seems there is no built-in way to do that. It's pretty easy to deal with without step functions by creating records in the database and running cron jobs, but I'm hoping to get some advice on how to deal with this in an AWS way.

I've tried to add a "wait for callback" statement to the initial function which sends the first email, so that's how I can put a timeout 2 months on that task, so it'll fail after 2 months if I don't send "sendTaskSuccess" by clicking the link inside the email. But in this case, I don't know how to deal with reminders.

Another thing I've tried is to delegate reminders to another state machine and execute that state machine after initiating the first email. Basically workflow inside the workflow. But the problem here is that I cannot cancel the child workflow (it has the same task token as the parent) when the parent is successful (user clicked the link), it stays and sends reminders even after the parent step is gone.

Thanks for any advice!

Upvotes: 1

Views: 580

Answers (1)

diegosantiviago
diegosantiviago

Reputation: 1078

One way of handling the timeout is to catch either States.Timeout or States.HeartbeatTimeout and move to the next reminder state.

There is a pattern for more complicated cases. You can have a Parallel branch with both your Callback Task and your Wait state. When you call SendTaskSuccess, you also want to complete the Parallel state and not wait for the Wait state to complete. If you don't receive a call to SendTaskSuccess, your Wait state will fire and can move to a Fail state. You also need to add the Catch statements to your parallel to control the execution flow (complete or enter another reminder).

There is a recent blog post about these early out patterns here:

https://aws.amazon.com/blogs/compute/implementing-patterns-that-exit-early-out-of-a-parallel-state-in-aws-step-functions/

Upvotes: 0

Related Questions