AtlassianPS / JiraPS

PowerShell module to interact with Atlassian JIRA
https://AtlassianPS.org/module/JiraPS
MIT License
321 stars 131 forks source link

Invoke-WebRequest from JiraPS does not use MaximumRetryCount #505

Open IonutDanNica opened 5 months ago

IonutDanNica commented 5 months ago

Context

Is your feature request related to a problem? Please describe.

I work with a Jira instance that has really low API limits - 50 requests and 10 new requests per minute, so I was thinking maybe it was possible to use MaximumRetryCount parameter from Invoke-Webrequest to retry the request. The native powershell Invoke-webrequest has support for this since version 7.4, but the IWR function inside jiraPS does not have this as a usable parameter.

Description

Describe the solution you'd like

Is it possible to: 1 - drop the use of a custom IWR (not sure if this was for historical reasons or otherwise) if using powershell core or newer 2 - adjust the IWR function to accept newer supported parameters from native Powershell IWR so that JiraPS can properly throttle itself 3 - Add some sort of timer to retry the IWR command either after "x-RateLimit-Interval-Seconds" that is sent with every webresponse header or via some sort of loop, to retry until 'retry-after' from headers is zero.

Additional Information

The rate information as per Atlassian official docs:

When users make authenticated requests, they’ll see rate limiting headers in the response. These headers are added to every response, not just when you’re rate limited. Header Description X-RateLimit-Limit The maximum number of requests (tokens) you can ever have. New tokens won’t be added to your bucket after reaching this limit. Your admin configures this as Max requests. X-RateLimit-Remaining The remaining number of tokens. This is what you have and can use right now. X-RateLimit-Interval-Seconds The time interval in seconds. You get a batch of new tokens every such time interval. X-RateLimit-FillRate The number of tokens you get every time interval. Your admin configures this as __ Requests allowed. retry-after How long you need to wait until you get new tokens. You can send a request successfully when the retry-after header is set to 0 after several failures with the HTTP status code 429.