public async Task <OpenLibraryVersion> SaveArchive(OpenLibraryDownload version, CancellationToken ct) { var matchingVersion = await FindArchiveEntries(version.Datestamp.AddDays(-1), version.Datestamp.AddDays(1), version.ArchiveType, ct); if (matchingVersion?.Any(v => v.PublishDate == version.Datestamp) == true) { throw new ArgumentException($"{version.ArchiveType.GetKey()} is already in the archives"); } var transferReport = await _storageStreamer.StreamHttpToS3(version.Source, _openLibVersionsBucket, version.ObjectName, ct); var versionEntry = new OpenLibraryVersion { SourceUrl = version.Source, Kind = version.ArchiveType.GetKey(), ObjectName = version.ObjectName, Bytes = transferReport.Bytes, Uri = transferReport.DestinationUrl, PublishDate = version.Datestamp, }; await SaveArchiveEntry(versionEntry, ct); return(versionEntry); }
public async Task SaveArchiveEntry(OpenLibraryVersion version, CancellationToken ct) { _log.LogInformation($"Writing OpenLib entry {version.ObjectName} to archive index"); var timer = Stopwatch.StartNew(); await _pocoClient.SaveAsync(version, ct); timer.Stop(); _log.LogInformation($"Writing entry {version.ObjectName} saved to archive index in {timer.ElapsedMilliseconds:N0}ms"); }