redcap-api icon indicating copy to clipboard operation
redcap-api copied to clipboard

configured HttpClient.Timeout

Open 274188A opened this issue 10 months ago • 1 comments

I'm making a large Import request and sometimes I see the following error:

The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.

Is there anywhere in this package where we can increase the timeout?

Thanks

274188A avatar Apr 29 '24 06:04 274188A

Here's a possible way to do this:

 /// <summary>
 /// Sends request using http
 /// </summary>
 /// <param name="redcapApi"></param>
 /// <param name="payload">data</param>
 /// <param name="uri">URI of the api instance</param>
 /// <param name="cancellationToken"></param>
 /// <param name="timeOutSecs"></param>
 /// <returns></returns>
 public static async Task<string> SendPostRequestAsync(this RedcapApi redcapApi,
                                                       Dictionary<string, string> payload,
                                                       Uri uri,
                                                       CancellationToken cancellationToken = default,
                                                       long timeOutSecs = 100)
 {
     try
     {
         string _responseMessage;
                         
         TimeSpan tsTimeOut = TimeSpan.FromTicks(timeOutSecs * TimeSpan.TicksPerSecond);                

         using var handler = GetHttpHandler();
         using var client = new HttpClient(handler);
         client.Timeout = tsTimeOut;

<snipped>

importRecordsResults = await this.SendPostRequestAsync(payload, _uri, cancellationToken: cancellationToken, 180L);

274188A avatar Apr 30 '24 02:04 274188A

@274188A Did you want to make a PR for this? I can also brew up initial draft for you to approve. What do you think? I should have something going by tomorrow.

tranpl avatar May 09 '24 01:05 tranpl

sure np - kind of busy atm but will get to it

274188A avatar May 09 '24 01:05 274188A

#125 merged 1.3.5 soon

tranpl avatar May 09 '24 01:05 tranpl