mbr/elm-again/1.0.0

NOTE: the latest version is 1.0.1

Again.Task

Run tasks with a retry policy. The first attempt runs immediately; the schedule controls the waits between subsequent attempts.

Retry a GET up to three total attempts on timeouts or network errors:

import Again.Http
import Again.Policy as Policy
import Again.Schedule exposing (Schedule(..))
import Again.Task exposing (retryIf)
import Http
import Task


type Msg
    = ReceivedResponse (Result Http.Error String)


loadMessage : Cmd Msg
loadMessage =
    Http.task
        { method = "GET"
        , headers = []
        , url = "/message.txt"
        , body = Http.emptyBody
        , resolver = Http.stringResolver Again.Http.resolve
        , timeout = Just 5000
        }
        |> retryIf isTransient
            { schedule = Periodic { delay = 1000 }
            , limit = Policy.MaxAttempts 3
            }
        |> Task.attempt ReceivedResponse


isTransient : Http.Error -> Bool
isTransient error =
    error == Http.Timeout || error == Http.NetworkError
retry : Policy -> Task error value -> Task error value

Retries any failure until the task succeeds or the attempt limit is reached.

retryIf : (error -> Bool) -> Policy -> Task error value -> Task error value

Retries only errors accepted by the predicate. Returns the last error when it is rejected or the attempt limit is reached.

For HTTP tasks, Again.Http.isRetryable supplies a default predicate.

retryWith : (error -> Decision) -> Policy -> Task error value -> Task error value

Classifies each error with a Decision. RetryAfter waits for the greater of the requested delay and the policy's delay. Returns the last error when stopped or when the attempt limit is reached.