genretry: simple exponential backoff in elixir

15
GenRetry if at first you don't succeed pete gamache // ElixirConf 2016 // @gamache

Upload: pete-gamache

Post on 16-Feb-2017

328 views

Category:

Software


3 download

TRANSCRIPT

Page 1: GenRetry: Simple Exponential Backoff in Elixir

GenRetryif at first you don't succeed

pete gamache // ElixirConf 2016 // @gamache

Page 2: GenRetry: Simple Exponential Backoff in Elixir

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

• Your code is perfectWorks first time, every time

• I am not you

Page 4: GenRetry: Simple Exponential Backoff in Elixir

(my code)

Page 5: GenRetry: Simple Exponential Backoff in Elixir

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

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

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

Background Process

Page 9: GenRetry: Simple Exponential Backoff in Elixir
Page 10: GenRetry: Simple Exponential Backoff in Elixir

GenRetry.retry

Page 11: GenRetry: Simple Exponential Backoff in Elixir

Task.async

Page 12: GenRetry: Simple Exponential Backoff in Elixir
Page 13: GenRetry: Simple Exponential Backoff in Elixir

GenRetry.Task.async

Page 14: GenRetry: Simple Exponential Backoff in Elixir

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

Thanks!