Giter VIP home page Giter VIP logo

Comments (4)

jon-batscha avatar jon-batscha commented on September 28, 2024

Hey,

Thanks for reaching out, and apologies for the late response.

I'm wondering if this is due to our built-in retries.

Can you try altering the retry settings; that may lower the wait time that causes the gunicorn timeout.

For reference, the retry settings (with default values) at the client level are:

klaviyo = KlaviyoAPI("YOUR_API_KEY_HERE", max_delay=60, max_retries=3)

where max_delay is the total delay across all retry attempts.

If you'd like to turn off retries altogether and implement your own error handling, you can set:

klaviyo = KlaviyoAPI("YOUR_API_KEY_HERE", max_delay=0, max_retries=0)

from klaviyo-api-python.

odedva avatar odedva commented on September 28, 2024

hey @jon-batscha - qq regarding retries mechanism - on what status codes does the library makes retries?
we occasionally get 502 responses (like once a day, usually multiple of those at the same time) from the klaviyo api, and not sure if the client library makes a retry on those.
seems to us that it does not and wanted to double check that with you...
also, we would like to use the _request_timeout variable to use that and i'm not sure how does that combines with the max_delay and max_retry when setting the API class.

last time we saw this was around 23:00 UTC time Aug 28th..
example of error response we see in our logs (seems also something with cloudflare?)
image

from klaviyo-api-python.

jon-batscha avatar jon-batscha commented on September 28, 2024

Hi Oded,

Thanks for reaching out, great question!

I actually just updated the retry logic in today’s release (thanks to your feedback), so what I’ll describe below applies to versions 5.3.0 and later:

we retry on the following error codes:

    _STATUS_CODE_CONNECTION_RESET_BY_PEER = 104
    _STATUS_CODE_TOO_MANY_REQUESTS = 429
    _STATUS_CODE_SERVICE_UNAVAILABLE = 503
    _STATUS_CODE_GATEWAY_TIMEOUT = 504
    _STATUS_CODE_A_TIMEOUT_OCCURED = 524

NOTE: we do not retry on 502 errors, as those are not guaranteed to be transient, and so retrying on those could hold up jobs. That said, our API team is aware of the occasional 502s and is working to fix this on our end (at the API-level).

In terms of the retry logic: we currently take the following 2 params:

  • max_delay
  • max_retries

We retry up to max_retries, using the following algorithm: wait_random_exponential

The algorithm starts with a 1 second wait, and at each retry, doubles the wait time, up to max_delay

Given this updated logic, we now recommend the following default values (now reflected in our defaults/readme:

  • max_delay = 60
  • max_retries = 7

With this setting, the SDK will behave as follows:


  1. First request, no delay
  2. Second request, wait 1 second before retrying
  3. … wait 2 seconds before retrying
  4. … wait 4 seconds …
  5. … 8 seconds …
  6. … 16 seconds …
  7. … 32 seconds …

At this point, if no success, we’ll stop retrying.

You can find the code that implements retry logic and sets retry codes here.

Hopefully this answers your question. Please do not hesitate to reach out if you run into any further issues.

(I also received your email yesterday, will follow up on the questions you sent over there in a bit)

from klaviyo-api-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.