Пример #1
0
        public async Task <AvalancheRunResult> Run()
        {
            var result = new AvalancheRunResult();

            var catalogId        = _lightroom.GetCatalogId();
            var allPictures      = _lightroom.GetAllPictures();
            var filteredPictures = allPictures
                                   .GroupBy(a => a.FileId)
                                   .Select(a => a.First())
                                   .Where(a => a.LibraryCount > 0 &&
                                          !_avalanche.FileIsArchived(a.FileId))
                                   .ToList();

            _logger.LogInformation("Backing up {0} images", filteredPictures.Count);

            await _glacier.AssertVaultExists(_parameters.Glacier.VaultName);

            // todo: parallelize this if it improves uploads (not sure if it will)
            var index = 0;

            foreach (var f in filteredPictures)
            {
                var currentPath = Path.Combine(f.AbsolutePath, f.FileName);
                _logger.LogInformation("Archiving {0} of {1}: {2}", ++index, filteredPictures.Count, currentPath);

                // Retry for transient transport failures
                ArchivedPictureModel archive = null;
                for (var i = 0; i < RetryCount; ++i)
                {
                    try
                    {
                        archive = await _glacier.SaveImage(f, _parameters.Glacier.VaultName);

                        break;
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError("Error persisting file", ex);
                        continue;
                    }
                }

                if (archive == null)
                {
                    _logger.LogError("Failed 3 times to persist {0}, giving up", currentPath);
                    result.Failures.Add(f);
                    continue;
                }

                _avalanche.MarkFileAsArchived(archive, _parameters.Glacier.VaultName, _parameters.Glacier.Region, _parameters.Avalanche.CatalogFilePath, catalogId.ToString());
                result.Successes.Add(f);
            }

            _logger.LogInformation("Done");
            return(result);
        }
Пример #2
0
        public async Task Archiving_BeforeUploadingFiles_AssertsVaultExists()
        {
            // Cause the actual image call to fail hard and stop execution.
            // This will allow us to assert that the call to vault assertion
            // occurred prior to attempts to save images.
            _glacier.SaveImage(Arg.Any <PictureModel>(), Arg.Any <string>()).Returns(SaveImageFails);

            try
            {
                await _sut.Run();
            }
            catch
            {
                // This will fail because of the wireup, nothing to see here
            }

            await _glacier.ReceivedWithAnyArgs(1).AssertVaultExists(Arg.Any <string>());
        }