File tree Expand file tree Collapse file tree 1 file changed +19
-8
lines changed
Snittlistan.Web/Infrastructure/Bits Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change 11#nullable enable
22
3+ using System . Diagnostics ;
4+ using System . Net ;
35using System . Net . Http ;
46using System . Runtime . Caching ;
57using System . Text ;
@@ -148,13 +150,22 @@ private async Task<TResult> Post<TResult>(object body, string url)
148150
149151 private async Task < string > Request ( HttpMethod method , string url , Action < HttpRequestMessage > action )
150152 {
151- Logger . InfoFormat (
152- "Requesting {url}" ,
153- url ) ;
154- HttpRequestMessage request = new ( method , url ) ;
155- action . Invoke ( request ) ;
156- HttpResponseMessage result = await client . SendAsync ( request ) ;
157- string content = await result . EnsureSuccessStatusCode ( ) . Content . ReadAsStringAsync ( ) ;
158- return content ;
153+ Stopwatch sw = Stopwatch . StartNew ( ) ;
154+ while ( true )
155+ {
156+ Logger . InfoFormat (
157+ "Requesting {url}" ,
158+ url ) ;
159+ HttpRequestMessage request = new ( method , url ) ;
160+ action . Invoke ( request ) ;
161+ HttpResponseMessage response = await client . SendAsync ( request ) ;
162+ if ( ( int ) response . StatusCode != 429 || sw . Elapsed . TotalSeconds > 60 )
163+ {
164+ string content = await response . EnsureSuccessStatusCode ( ) . Content . ReadAsStringAsync ( ) ;
165+ return content ;
166+ }
167+
168+ await Task . Delay ( 1000 ) ;
169+ }
159170 }
160171}
You can’t perform that action at this time.
0 commit comments