genretry: simple exponential backoff in elixir
TRANSCRIPT
![Page 1: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/1.jpg)
GenRetryif at first you don't succeed
pete gamache // ElixirConf 2016 // @gamache
![Page 2: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/2.jpg)
TL;DR
• GenRetry provides retry with exponential backoff for any function that raises an exception when it fails
• Use it, it's easy
• https://github.com/appcues/gen_retry
![Page 3: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/3.jpg)
• Your code is perfectWorks first time, every time
• I am not you
![Page 4: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/4.jpg)
(my code)
![Page 5: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/5.jpg)
J/K, your code fails too
• Failures happen
• Minimizing failures is nice
• Handling failures is even nicer
• Primary weapon: repetition
![Page 6: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/6.jpg)
Exponential Backoff
• Set an initial retry delay
• Every time you retry, double the previous delay
• Examples are everywhere
• Optional: jitter adds a random percentage of delay
![Page 7: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/7.jpg)
GenRetry basics
• GenRetry.retry/2 handles background processes where we don't care about the output -- replaces spawn_link
• GenRetry.Task.async/2 handles future/promise-style tasks where we do care about the output --> replaces Task.async
![Page 8: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/8.jpg)
Background Process
![Page 9: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/9.jpg)
![Page 10: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/10.jpg)
GenRetry.retry
![Page 11: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/11.jpg)
Task.async
![Page 12: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/12.jpg)
![Page 13: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/13.jpg)
GenRetry.Task.async
![Page 14: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/14.jpg)
In conclusion
• Let it crash -- on your terms
• Check out our other tools! https://github.com/appcues/
![Page 15: GenRetry: Simple Exponential Backoff in Elixir](https://reader034.vdocuments.site/reader034/viewer/2022042505/58a4bcac1a28ab2d688b6551/html5/thumbnails/15.jpg)
Thanks!