Commit 69012f32 authored by justcoding121's avatar justcoding121

minor refactor in retry policy

parent fe1fac01
using Polly; using Polly;
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Titanium.Web.Proxy.Network.Tcp; using Titanium.Web.Proxy.Network.Tcp;
...@@ -14,10 +13,14 @@ namespace Titanium.Web.Proxy.Network ...@@ -14,10 +13,14 @@ namespace Titanium.Web.Proxy.Network
private TcpServerConnection currentConnection; private TcpServerConnection currentConnection;
private Exception exception; private Exception exception;
private Policy policy;
internal RetryPolicy(int retries, TcpConnectionFactory tcpConnectionFactory) internal RetryPolicy(int retries, TcpConnectionFactory tcpConnectionFactory)
{ {
this.retries = retries; this.retries = retries;
this.tcpConnectionFactory = tcpConnectionFactory; this.tcpConnectionFactory = tcpConnectionFactory;
policy = getRetryPolicy();
} }
/// <summary> /// <summary>
...@@ -31,11 +34,13 @@ namespace Titanium.Web.Proxy.Network ...@@ -31,11 +34,13 @@ namespace Titanium.Web.Proxy.Network
Func<Task<TcpServerConnection>> generator, TcpServerConnection initialConnection) Func<Task<TcpServerConnection>> generator, TcpServerConnection initialConnection)
{ {
currentConnection = initialConnection; currentConnection = initialConnection;
exception = null;
try try
{ {
//retry on error with polly policy //retry on error with polly policy
//do not use polly context to store connection; it does not save states b/w attempts //do not use polly context to store connection; it does not save states b/w attempts
await getRetryPolicy().ExecuteAsync(async () => await policy.ExecuteAsync(async () =>
{ {
//setup connection //setup connection
currentConnection = currentConnection as TcpServerConnection ?? currentConnection = currentConnection as TcpServerConnection ??
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment