Comments (12)
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.
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.
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.
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.
that could work as something reusable - how do we feel about whether it should be enabled or disabled by default?
from slack-notifier.
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.
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.
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.
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 inRetry-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.
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.
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.
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
slack-notifier/lib/slack-notifier.rb
Line 19 in e9aace7
from slack-notifier.
Related Issues (20)
- Slack Notifier & Singleton ? HOT 2
- Allow support for legacy/bot tokens, not just webhooks
- Link formatting not working correctly for markdown links inside parenthesis
- tagging someone does not tag them HOT 6
- Notification seems not send always HOT 1
- Does this gem support Slack's new 'block' message format? HOT 3
- Markdown links containing [ and ] are broken HOT 4
- ping with channel option does not override webhook channel HOT 3
- Usernames with spaces HOT 3
- Ruby 2.7 deprecation warnings HOT 1
- ⚠️ looking for a maintainer ⚠️ HOT 4
- Ruby 3.0.0, LinkFormatter, positional/keyword/default arguments issue on #initialize HOT 6
- Is there any way to send postEphemeral?
- Exclusion of inactive/merged branches
- channel and username params doesn't work HOT 2
- Customize private messages webhook bot
- How to not use ssl? HOT 16
- Gem available in rubygem.org doesn't match this code HOT 1
- Is the stack trace limited? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slack-notifier.