public async Task SaveUpdates(IAnalyticsStorage analyticsStorage, int maxAttempts = 5)
        {
            await savingSemaphore.WaitAsync();

            try
            {
                var frames = PriceHistoryManager.PullUpdates();
                if (frames.Count < 1)
                {
                    return;
                }
                var attempt = 0;
                while (attempt < maxAttempts)
                {
                    try
                    {
                        var frameModels = frames.Select(f => f.ToFrameModel()).ToList();
                        await analyticsStorage.SaveAnalytics(frameModels);

                        break;
                    }
                    catch
                    {
                        attempt++;
                        if (attempt == maxAttempts)
                        {
                            throw;
                        }
                        Thread.Sleep(attempt * 500);
                    }
                }
            }
            finally
            {
                savingSemaphore.Release();
            }
        }
Пример #2
0
        public async Task SaveUpdates(IAnalyticsStorage analyticsStorage, int numberOfTries = 5)
        {
            await savingSemaphore.WaitAsync();

            try
            {
                var frames = PriceHistoryManager.PullUpdates();
                if (frames.Count < 1)
                {
                    return;
                }
                var currentTry = 0;
                while (currentTry < numberOfTries)
                {
                    try
                    {
                        var frameModels = frames.Select(f => f.ToFrameModel()).ToList();
                        await analyticsStorage.SaveAnalytics(frameModels);

                        break;
                    }
                    catch
                    {
                        currentTry++;
                        if (currentTry == numberOfTries)
                        {
                            throw;
                        }
                        Thread.Sleep(currentTry * 500);
                    }
                }
            }
            finally
            {
                savingSemaphore.Release();
            }
        }