configured HttpClient.Timeout #123

Closed
opened 2024-04-29 02:52:02 -04:00 by 274188A · 4 comments
274188A commented 2024-04-29 02:52:02 -04:00 (Migrated from github.com)

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

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 commented 2024-04-29 22:43:25 -04:00 (Migrated from github.com)

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);

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);
tranpl commented 2024-05-08 21:00:10 -04:00 (Migrated from github.com)

@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.

@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.
274188A commented 2024-05-08 21:01:43 -04:00 (Migrated from github.com)

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

sure np - kind of busy atm but will get to it
tranpl commented 2024-05-08 21:19:55 -04:00 (Migrated from github.com)

#125 merged
1.3.5 soon

#125 merged 1.3.5 soon
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
tranpl/redcap-api#123
No description provided.