private async Task CommitResults() { _Logger.LogInformation($"Commit results - publish EKSs."); await using (_PublishingDbContext.BeginTransaction()) { var move = _PublishingDbContext.Set <EksCreateJobOutputEntity>().Select( x => new ExposureKeySetContentEntity { Created = _Start, Release = x.Release, ContentTypeName = MediaTypeNames.Application.Zip, Content = x.Content, CreatingJobName = x.CreatingJobName, CreatingJobQualifier = x.CreatingJobQualifier, PublishingId = _PublishingId.Create(x.Content) }).ToArray(); await using (_ContentDbContext.BeginTransaction()) { _ContentDbContext.Set <ExposureKeySetContentEntity>().AddRange(move); _ContentDbContext.SaveAndCommit(); } } _Logger.LogInformation($"Commit results - Mark TEKs as Published."); await using (_PublishingDbContext.BeginTransaction()) //Read-only { await using (_WorkflowDbContext.BeginTransaction()) { var count = 0; var used = _PublishingDbContext.Set <EksCreateJobInputEntity>() .Where(x => x.Used) .Skip(count) .Select(x => x.Id) .Take(100) .ToArray(); while (used.Length > 0) { var zap = _WorkflowDbContext.TemporaryExposureKeys .Where(x => used.Contains(x.Id)) .ToList(); foreach (var i in zap) { i.PublishingState = PublishingState.Published; } await _WorkflowDbContext.BulkUpdateAsync(zap, x => x.PropertiesToInclude = new List <string> { nameof(TemporaryExposureKeyEntity.PublishingState) }); count += used.Length; used = _PublishingDbContext.Set <EksCreateJobInputEntity>() .Where(x => x.Used) .Skip(count) .Select(x => x.Id) .Take(100) .ToArray(); } _WorkflowDbContext.SaveAndCommit(); } _Logger.LogInformation($"Cleanup job tables."); await _PublishingDbContext.Set <EksCreateJobInputEntity>().BatchDeleteAsync(); await _PublishingDbContext.Set <EksCreateJobOutputEntity>().BatchDeleteAsync(); _PublishingDbContext.SaveAndCommit(); } }
public async Task CommitResults() { await using (_ContentDbContext.BeginTransaction()) { var move = _ContentDbContext.EksOutput.Select( x => new ExposureKeySetContentEntity { Release = x.Release, Content = x.Content, ContentTypeName = MediaTypeNames.Application.Zip, CreatingJobName = x.CreatingJobName, CreatingJobQualifier = x.CreatingJobQualifier, PublishingId = _PublishingId.Create(x.Content) }).ToArray(); //TODO copy? Cos it's the same DB cos 'policy' _ContentDbContext.ExposureKeySetContent.AddRange(move); _ContentDbContext.SaveAndCommit(); } await using (_ContentDbContext.BeginTransaction()) //Read-only await using (_WorkflowDbContext.BeginTransaction()) { var count = 0; var used = _ContentDbContext.Set <EksCreateJobInputEntity>() .Where(x => x.Used) .Skip(count) .Select(x => x.Id) .Take(100) .ToArray(); while (used.Length > 0) { var zap = _WorkflowDbContext.TemporaryExposureKeys .Where(x => used.Contains(x.Id)) .ToList(); foreach (var i in zap) { i.PublishingState = PublishingState.Published; } await _WorkflowDbContext.BulkUpdateAsync(zap, x => x.PropertiesToInclude = new List <string>() { nameof(TemporaryExposureKeyEntity.PublishingState) }); count += used.Length; used = _ContentDbContext.Set <EksCreateJobInputEntity>() .Where(x => x.Used) .Skip(count) .Select(x => x.Id) .Take(100) .ToArray(); } _WorkflowDbContext.SaveAndCommit(); } await _ContentDbContext.EksInput.BatchDeleteAsync(); await _ContentDbContext.EksOutput.BatchDeleteAsync(); _ContentDbContext.SaveAndCommit(); }