Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

Latest commit

 

History

History
37 lines (22 loc) · 2.83 KB

repeat_until_successful.md

File metadata and controls

37 lines (22 loc) · 2.83 KB

Repeat Until Successful

There are many instances in which you want to keep trying something until it is done (or just want to wait until certain conditions are met). This construct provides a way for you to do this.

You can find a link to the playbook and its documentation below.

For now, we'll walk through the app to get an idea of how it works. Here is the full playbook:

A picture of the complete playbook

The basic flow of this playbook is:

  1. Attempt an http request to the playbook specified by the link URL query parameter.
  2. If the http request from step 1 works:
    • Make a request to finalLink
  3. If the http request from step 1 does not work (returns 40X error):
    • Increment the count which keeps track of the number of times we have tried to trigger the other playbook
    • If the count is less than the max number of attempts: wait for twenty seconds and make another attempt
    • If the count is equal to the max number of attempts: stop and send a message (by default, a slack message)

So we first make a request to another playbook. The idea is that we have two playbooks, but we don't want to run the second playbook until the first one is successful. So, we'll make a request to the first playbook; if the first playbook fails (and returns some kind of 400 response), we'll increment the counter which keeps track of how many times we have made the request, wait for some time (20 seconds by default), and then try again. You can see this flow below (the inconsequential playbook apps for this process are blurred):

A picture of the normal execution of the playbook if the playbook we are requesting has not completed

Eventually, we will want to stop requesting the first playbook and give up (so we don't get stuck making requests for sempiternity). There is a max value that you send the app to tell it when to give up. If the playbook has tried the maximum number of times, it will fail and send a slack message (you can configure it to send a message in a different medium). This flow looks like:

A picture of the flow if the maximum number of attempts has been met

If we request the first playbook for a bit and then it finally succeeds before the maximum number of requests are made, then a request is made to the playbook at the finalLink. This flow looks like:

A picture of the flow if the playbook we are requesting completes successfully

Links

You can find documentation for the playbook to support this construct here.

You can find the actual playbook here.