GithubHelp home page GithubHelp logo

Comments (12)

siegy22 avatar siegy22 commented on May 26, 2024

I don't think that's the way to deal with an API rate limit, especially if it contains something like sleep(rand(1..10)). If you hit the rate limit, check why you're hitting it. Are you running a loop which does a lot of API requests which can be improved? Can you "verify" your application to not hit a rate limit as small as you're hitting it right now?

from slack-notifier.

anchit-desai avatar anchit-desai commented on May 26, 2024

The functions that call the API are invoked by user actions, so it's hard for us to tell when these will occur.

from slack-notifier.

paprikati avatar paprikati commented on May 26, 2024

I personally think the implementation of a backoff strategy is going to vary for each caller. I'm not sure there's a nice 'standard' approach we could apply within the gem that would be useful for lots of people

from slack-notifier.

rjhancock avatar rjhancock commented on May 26, 2024

https://api.slack.com/docs/rate-limits , specifically under Responding to rate limiting conditions, will give you a time interval to use instead of the sleep command.

Probably a better approach.

from slack-notifier.

paprikati avatar paprikati commented on May 26, 2024

that could work as something reusable - how do we feel about whether it should be enabled or disabled by default?

from slack-notifier.

rjhancock avatar rjhancock commented on May 26, 2024

I think it's something that should be non-optional. Have the gem just handle it and make a note in the documentation.

from slack-notifier.

paprikati avatar paprikati commented on May 26, 2024

should we retry infinitely? that seems sad... or keep a count of the number of attempts and cap it at 2 or 3? wdyt

from slack-notifier.

rjhancock avatar rjhancock commented on May 26, 2024

I think utilizing the Retry content would be fine as eventually it'll get through unless someone is doing a very high volume of messages.

from slack-notifier.

paprikati avatar paprikati commented on May 26, 2024

I don't think retrying infinitely is a good idea as you can potentially lock up the thread forever (e.g. if you have some other service that is hammering slack for some reason, and you are sending slack messages in your production process rather than in a worker). I agree it requires a weird set of bugs to happen, but I wouldn't want to bring someone down like that (it would be super sad)

I propose we add this as optional behaviour (so its not a breaking change) as someone might want to handle the retries themselves (e.g. by enqueuing a new worker) rather than letting a thread sleep - for example that's what we do.

I think we should provide the following options:

  • max_attempts (default 3, set to 0 for infinite)
  • max_sleep_time (default 30, measured in seconds) - so if there's a slack bug / weirdness where it returns a very large number in Retry-After then again your thread is not sitting dead for ages and ages. Slack's docs seem to suggest they usually send 1-3 seconds so you're unlikely to hit this anyway.

I also think we should also raise a specific error if a request is rate-limited (and we aren't retrying), which exposes the retry-after so a client can handle it.

I'll write a PR this week and see if I can get one of the maintainers to take a look

from slack-notifier.

saiqulhaq avatar saiqulhaq commented on May 26, 2024

this gem accepts custom HTTP client
you can use an HTTP client using this gem https://github.com/lostisland/faraday-retry that support exponential backoff
then use it as the README https://github.com/slack-notifier/slack-notifier#custom-http-client
so can we close this issue?

from slack-notifier.

pedros007 avatar pedros007 commented on May 26, 2024

this gem accepts custom HTTP client

Can anyone provide an example using Faraday as an alternate HTTP client? The example in the faraday-retry repo shows how to create a Faraday connection, not a client as required by the slack-notifier Gem API.

from slack-notifier.

saiqulhaq avatar saiqulhaq commented on May 26, 2024

this gem accepts custom HTTP client

Can anyone provide an example using Faraday as an alternate HTTP client? The example in the faraday-retry repo shows how to create a Faraday connection, not a client as required by the slack-notifier Gem API.

@pedros007 you just need to create a custom faraday instance with retry middleware, then pass http_client

config.http_client(options.delete(:http_client)) if options.key?(:http_client)

from slack-notifier.

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.