britzl / aws-sdk-lua

Auto generated AWS SDK for Lua
Apache License 2.0
38 stars 10 forks source link

[Question] Are retries supported? #8

Open SirLynix opened 5 years ago

SirLynix commented 5 years ago

According to https://docs.aws.amazon.com/general/latest/gr/api-retries.html, every AWS should implement a retry mecanism because basically, "shit happens".

Does the Lua SDK implement this? If not, where can it be implemented in a simple way?

britzl commented 5 years ago

The Lua SDK does not support retries. I would probably implement retries on top of the SDK in a way that works within the environment the code is run in. In a Lua game engine such as Defold I'd probably do something like this:

local function retry(api_fn, request, cb)
    local co = coroutine.create(function()
        local delay = 2
        local attempts_left = 5
        while attempts_left > 0 do
            local response, error_type, error_message = api_fn(request)
            if response then
                cb(response)
                return
            end
            timer.delay(delay, false, function()
                coroutine.resume(co)
            end)
            coroutine.yield()
            delay = delay * 2
            attempts_left = attempts_left - 1
        end
        cb(false, "Retries failed")
    end)
end

retry(gamelift.CreateGameSessionSync, gamelift.CreateGameSessionInput(), function(response, err)
...
end)