Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Nic/unresponsive server #133

Merged
merged 3 commits into from
Sep 10, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Minimum set of changes that could enable Grasshopper files these to b…
…e opened: those which have embedded SpeckleApiClients pointing to a server which is currently unresponsive.
  • Loading branch information
nic-burgers-arup committed Sep 9, 2019
commit 9722f10a4323d92b9c6b954f48125ee90bb65d8a
25 changes: 19 additions & 6 deletions ApiClient/SpeckleApiClientApiCalls.cs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

@@ -324,7 +325,7 @@ public async System.Threading.Tasks.Task<ResponseUser> UserGetAsync( System.Thre
urlBuilder_.Append( BaseUrl != null ? BaseUrl.TrimEnd( '/' ) : "" ).Append( "/accounts" );

var client_ = GetHttpClient();
try
try
{
using ( var request_ = new System.Net.Http.HttpRequestMessage() )
{
@@ -394,7 +395,11 @@ public async System.Threading.Tasks.Task<ResponseUser> UserGetAsync( System.Thre
}
}
}
finally
catch (TaskCanceledException)
{
throw new SpeckleException("Connection timeout with Speckle Server", (int)HttpStatusCode.RequestTimeout, null, null, null);
}
finally
{
if ( client_ != null )
client_.Dispose();
@@ -2321,11 +2326,11 @@ public async System.Threading.Tasks.Task<ResponseStream> StreamGetAsync( string
if ( query != null ) urlBuilder_.Append( query );

var client_ = GetHttpClient();
try
try
{
using ( var request_ = new System.Net.Http.HttpRequestMessage() )
{
request_.Method = new System.Net.Http.HttpMethod( "GET" );
request_.Method = new System.Net.Http.HttpMethod( "GET" );
request_.Headers.Accept.Add( new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue( "application/json" ) );

PrepareRequest( client_, request_, urlBuilder_ );
@@ -2391,7 +2396,11 @@ public async System.Threading.Tasks.Task<ResponseStream> StreamGetAsync( string
}
}
}
finally
catch (TaskCanceledException)
{
throw new SpeckleException("Connection timeout with Speckle Server", (int)HttpStatusCode.RequestTimeout, null, null, null);
}
finally
{
if ( client_ != null )
client_.Dispose();
@@ -2688,6 +2697,10 @@ public async System.Threading.Tasks.Task<ResponseObject> StreamGetObjectsAsync(

return default( ResponseObject );
}
catch(TaskCanceledException)
{
throw new SpeckleException("Connection timeout with Speckle server", (int) HttpStatusCode.RequestTimeout, null, null, null);
}
finally
{
if ( response_ != null )
@@ -3412,7 +3425,7 @@ public async System.Threading.Tasks.Task<ResponseObject> ObjectGetBulkAsync( str
if ( query != null ) urlBuilder_.Append( query );


var client_ = GetHttpClient();
var client_ = GetHttpClient(defaultBulkTimeoutMilliseconds);
try
{
using ( var request_ = new System.Net.Http.HttpRequestMessage() )
4 changes: 4 additions & 0 deletions ApiClient/SpeckleApiClientExtension.cs
Original file line number Diff line number Diff line change
@@ -55,6 +55,10 @@ public partial class SpeckleApiClient : ISerializable

Timer IsReady, WsReconnecter;

//Default timeouts, pending further discussion
private double defaultTimeoutMilliseconds = 3000;
private double defaultBulkTimeoutMilliseconds = 60000;

private Dictionary<string, SpeckleObject> ObjectCache = new Dictionary<string, SpeckleObject>();


13 changes: 9 additions & 4 deletions ApiClient/SpeckleApiClientHead.cs
Original file line number Diff line number Diff line change
@@ -41,11 +41,16 @@ partial void PrepareRequest( HttpClient client, HttpRequestMessage request, stri
request.Content = new GzipContent( request.Content );
}

private HttpClient GetHttpClient( )
private HttpClient GetHttpClient(double timeoutMillisecondsOverride = 0)
{
var handler = new HttpClientHandler();
handler.AutomaticDecompression = System.Net.DecompressionMethods.GZip;
return new HttpClient( handler, true );
var handler = new HttpClientHandler
{
AutomaticDecompression = System.Net.DecompressionMethods.GZip
};
return new HttpClient(handler, true)
{
Timeout = TimeSpan.FromMilliseconds(timeoutMillisecondsOverride == 0 ? defaultTimeoutMilliseconds : timeoutMillisecondsOverride)
};
}
}
}