claytondus / Claytondus.AmazonMWS

.NET Standard fork of Amazon MWS client
https://developer.amazonservices.com/
Apache License 2.0
33 stars 12 forks source link

No Quotas in ResponseHeaderMetaData - Fallback mechanism? #4

Closed pykong closed 6 years ago

pykong commented 6 years ago

It would be highly desirable to have access to the remaining quota of a response type to avoid throtteling. Unfortunately I never found quotaMax, quotaRemaining and quotaResetsAt always to be null when using your package. Request types used: ListOrders, ListOrderItems and ListFinancialEvents and their respective next token counterpart.

The reason those are missing is likely they are not provided in the first place by amazon's API. Their docs could be read that only those requests with an hourly cap provide quotas in their response headers:

https://docs.developer.amazonservices.com/en_DE/dev_guide/DG_Throttling.html See also: https://stackoverflow.com/questions/34961745/getting-amazon-mws-throttling-limits

Could you maybe endow your package with a fallback mechanism that keeps track of requests for us and calculates quotaRemaining and quotaResetsAt?

claytondus commented 6 years ago

The quota stats are returned if they are present in the responses. I believe you and the docs are correct, there is no quota data returned for those calls because they have no hourly quota (and the quota metadata only reflects the hourly quota, not the maximum request quota / restore rate). The only case where the hourly quota was provided and wasn't returned in the library is in the Feeds/Reports module, I will publish an update today that fixes that (Amazon never updated their code to provide this). Since the other endpoints don't have an hourly quota, I don't think it would be appropriate to implement it though the same mechanism, but rather to use whatever policing/shaping you need to manage the max request quota and restore rate. I use an in-memory token bucket at the moment, but I am planning on switching to Hangfire to schedule the calls and keep track of failed requests.

pykong commented 6 years ago

Will look into Hangfire, too. Thanks for the tip (and also for doing Amazon's job here ;-)).

claytondus commented 6 years ago

The Feeds/Reports module now has hourly quota data in ResponseHeaderMetadata.