Skip to content

Commit

Permalink
Merged in GUARD-784-Large-Intermittent-Sync-Delays (pull request #6)
Browse files Browse the repository at this point in the history
2020-08-31 GUARD-784 GUARD-780 Large-Intermittent-Sync-Delays

Approved-by: Maxim Strelsov
Approved-by: Slav Ivanyuk
  • Loading branch information
fabulaspb committed Oct 8, 2020
2 parents 230b9bc + cf1e163 commit 6b3a8aa
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 113 deletions.
2 changes: 1 addition & 1 deletion src/Global/GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
// [assembly: AssemblyVersion("1.0.*")]

// Keep in track with CA API version
[ assembly : AssemblyVersion( "1.4.2.0" ) ]
[ assembly : AssemblyVersion( "1.4.3.0" ) ]
1 change: 1 addition & 0 deletions src/ShipStationAccess/ShipStationAccess.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<Compile Include="V2\Models\TagList\ShipStationTag.cs" />
<Compile Include="V2\Services\DateTimeExtensions.cs" />
<Compile Include="V2\Services\JsonSerialization.cs" />
<Compile Include="V2\Services\PaginatedResponse.cs" />
<Compile Include="V2\Services\ParamsBuilder.cs" />
<Compile Include="V2\Services\WebRequestServices.cs" />
<Compile Include="V2\ShipStationService.cs" />
Expand Down
3 changes: 2 additions & 1 deletion src/ShipStationAccess/V2/IShipStationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
using ShipStationAccess.V2.Models.Store;
using ShipStationAccess.V2.Models.TagList;
using ShipStationAccess.V2.Models.WarehouseLocation;
using ShipStationAccess.V2.Services;

namespace ShipStationAccess.V2
{
public interface IShipStationService
{
IEnumerable< ShipStationOrder > GetOrders( DateTime dateFrom, DateTime dateTo, Func< ShipStationOrder, ShipStationOrder > processOrder = null );
Task< IEnumerable< ShipStationOrder > > GetOrdersAsync( DateTime dateFrom, DateTime dateTo, bool getShipmentsAndFulfillments = true, Func< ShipStationOrder, Task< ShipStationOrder > > processOrder = null );
Task< IEnumerable< ShipStationOrder > > GetOrdersAsync( DateTime dateFrom, DateTime dateTo, bool getShipmentsAndFulfillments = false, Func< ShipStationOrder, Task< ShipStationOrder > > processOrder = null, Action< IEnumerable< ReadError > > handleSkippedOrders = null );
IEnumerable< ShipStationOrder > GetOrders( string storeId, string orderNumber );

ShipStationOrder GetOrderById( string orderId );
Expand Down
28 changes: 16 additions & 12 deletions src/ShipStationAccess/V2/Misc/ActionPolicies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class ActionPolicies
{
public static ActionPolicy Submit
{
get { return _shipStationSumbitPolicy; }
get { return _shipStationSubmitPolicy; }
}

private static readonly ExceptionHandler _exceptionHandler = delegate( Exception x )
Expand All @@ -24,21 +24,23 @@ public static ActionPolicy Submit
return webX.Response.GetHttpStatusCode() != HttpStatusCode.Unauthorized;
};

private static readonly ActionPolicy _shipStationSumbitPolicy = ActionPolicy.With( _exceptionHandler ).Retry( 10, ( ex, i ) =>
private static readonly ActionPolicy _shipStationSubmitPolicy = ActionPolicy.With( _exceptionHandler ).Retry( 10, ( ex, i ) =>
{
ShipStationLogger.Log.Error( ex, "Retrying ShipStation API submit call for the {retryCounter} time", i );
SystemUtil.Sleep( TimeSpan.FromSeconds( 0.5 + i ) );
var delay = TimeSpan.FromSeconds( 0.5 + i );
ShipStationLogger.Log.Error( ex, "Retrying ShipStation API submit call for the {retryCounter} time, delay {delayInSeconds} seconds", i, delay.TotalSeconds );
SystemUtil.Sleep( delay );
} );

public static ActionPolicyAsync SubmitAsync
{
get { return _shipStationSumbitAsyncPolicy; }
get { return _shipStationSubmitAsyncPolicy; }
}

private static readonly ActionPolicyAsync _shipStationSumbitAsyncPolicy = ActionPolicyAsync.With( _exceptionHandler ).RetryAsync( 10, async ( ex, i ) =>
private static readonly ActionPolicyAsync _shipStationSubmitAsyncPolicy = ActionPolicyAsync.With( _exceptionHandler ).RetryAsync( 10, async ( ex, i ) =>
{
ShipStationLogger.Log.Error( ex, "Retrying ShipStation API submit call for the {retryCounter} time", i );
await Task.Delay( TimeSpan.FromSeconds( 0.5 + i ) );
var delay = TimeSpan.FromSeconds( 0.5 + i );
ShipStationLogger.Log.Error( ex, "Retrying ShipStation API submit call for the {retryCounter} time, delay {delayInSeconds} seconds", i, delay.TotalSeconds );
await Task.Delay( delay );
} );

public static ActionPolicy Get
Expand All @@ -48,8 +50,9 @@ public static ActionPolicy Get

private static readonly ActionPolicy _shipStationGetPolicy = ActionPolicy.With( _exceptionHandler ).Retry( 10, ( ex, i ) =>
{
ShipStationLogger.Log.Error( ex, "Retrying ShipStation API get call for the {retryCounter} time", i );
SystemUtil.Sleep( TimeSpan.FromSeconds( 0.5 + i ) );
var delay = TimeSpan.FromSeconds( 0.5 + i );
ShipStationLogger.Log.Error( ex, "Retrying ShipStation API get call for the {retryCounter} time, delay {delayInSeconds} seconds", i, delay.TotalSeconds );
SystemUtil.Sleep( delay );
} );

public static ActionPolicyAsync GetAsync
Expand All @@ -59,8 +62,9 @@ public static ActionPolicyAsync GetAsync

private static readonly ActionPolicyAsync _shipStationGetAsyncPolicy = ActionPolicyAsync.With( _exceptionHandler ).RetryAsync( 10, async ( ex, i ) =>
{
ShipStationLogger.Log.Error( ex, "Retrying ShipStation API get call for the {retryCounter} time", i );
await Task.Delay( TimeSpan.FromSeconds( 0.5 + i ) );
var delay = TimeSpan.FromSeconds( 0.5 + i );
ShipStationLogger.Log.Error( ex, "Retrying ShipStation API get call for the {retryCounter} time, delay {delayInSeconds} seconds", i, delay.TotalSeconds );
await Task.Delay( delay );
} );
}
}
27 changes: 27 additions & 0 deletions src/ShipStationAccess/V2/Services/PaginatedResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;

namespace ShipStationAccess.V2.Services
{
public sealed class PaginatedResponse< T > where T : class, new()
{
public int? TotalPagesExpected { get; set; }
public int? TotalEntitiesExpected { get; set; }
public int TotalPagesReceived { get; set; }

public List< T > Data { get; private set; }
public List< ReadError > ReadErrors { get; private set; }

public PaginatedResponse()
{
this.Data = new List< T >();
this.ReadErrors = new List< ReadError >();
}
}

public sealed class ReadError
{
public string Url { get; set; }
public int PageSize { get; set; }
public int Page { get; set; }
}
}
Loading

0 comments on commit 6b3a8aa

Please sign in to comment.