Example #1
0
        public static async Task HandleTransientsAsync(DbCommand cmd, Func <CancellationToken, Task> sqlAction, IRetryOnTransientErrorsStrategy strat, IDbProvider provider, CancellationToken cancel, SqlFuConfig config)
        {
start:
            try
            {
                config.OnCommand(cmd);
                await sqlAction(cancel).ConfigureFalse();
            }
            catch (DbException ex)
            {
                if (provider.IsTransientError(ex))
                {
                    "SqlFu".LogInfo("Transient error detected");
                    if (strat.CanRetry)
                    {
                        var period = strat.GetWaitingPeriod();
                        "SqlFu".LogInfo($"Waiting {period} before retrying");
                        await Task.Delay(period, cancel).ConfigureFalse();

                        "SqlFu".LogInfo("Retrying...");
                        goto start;
                    }
                    "SqlFu".LogWarn($"No more retries left. Tried {strat.RetriesCount} times. Throwing exception");
                }

                config.OnException(cmd, ex);
                throw;
            }
        }
Example #2
0
        public static void HandleTransients(DbCommand cmd, Action sqlAction, IRetryOnTransientErrorsStrategy strat, IDbProvider provider, SqlFuConfig cfg)
        {
start:
            try
            {
                cfg.OnCommand(cmd);
                sqlAction();
            }
            catch (DbException ex)
            {
                if (provider.IsTransientError(ex))
                {
                    "SqlFu".LogInfo("Transient error detected");
                    if (strat.CanRetry)
                    {
                        var period = strat.GetWaitingPeriod();
                        "SqlFu".LogInfo($"Waiting {period} before retrying");
                        Thread.Sleep(period);
                        "SqlFu".LogInfo("Retrying...");
                        goto start;
                    }
                    "SqlFu".LogWarn($"No more retries left. Tried {strat.RetriesCount} times. Throwing exception");
                }

                cfg.OnException(cmd, ex);
                throw;
            }
        }