grokability / jamf2snipe

Import and sync assets from a JAMFPro instance to Snipe-IT asset management.
MIT License
113 stars 55 forks source link

Replace rate-limit code with exponential backoff #116

Open uberbrady opened 1 year ago

uberbrady commented 1 year ago

So right now we have a lot of code throughout to handle backoff when rate-limits are exceeded - and it works very well, and I haven't heard a lot bad about it. But, I do have a few problems with it -

  1. The code repeats itself.
  2. The code generally retries only once.

According to the request docs here: https://requests.readthedocs.io/en/latest/user/advanced/#example-automatic-retries - there's a nice Retry system that we can use, which will automagically do exponential backoffs for us. I think we could use this by default, and then just remove the configuration options regarding backoff - just run as fast as you can, and back off when you have to. Maybe with an optional parameter about backoff duration settings?

The library https://urllib3.readthedocs.io/en/stable/reference/urllib3.util.html#urllib3.util.Retry which does those retries has a backoff_factor of 1 - which would give us sleeps of 1, 2, 4, 8 and so on, until we hit backoff_max (10 minutes maybe?) or total (10 retries maybe?). Could also make sense to have a far larger start backoff - 30 seconds, 10 seconds? - because in rate-limiting terms, 1, 2, 4, or 8 seconds isn't going to make a bit of difference.