public async Task Consume(ConsumeContext <GetAssetStatusRequest> context) { using (LogContext.PushProperty(nameof(context.ConversationId), context.ConversationId)) { Log.Information("Received {CommandName} command with conversationId {ConversationId} from the bus", nameof(GetAssetStatusRequest), context.ConversationId); var message = context.Message; // Prüfen, ob die Datei schon im Cache vorhanden ist. Wenn ja, ist alles gut. var response = await requestClient.Request(new DoesExistInCacheRequest { Id = context.Message.ArchiveRecordId, RetentionCategory = context.Message.RetentionCategory }); if (response.Exists) { Log.Information("Found the asset for id {ArchiveRecordId} with type {AssetType} and Size {FileSize} bytes in the cache.", message.ArchiveRecordId, message.AssetType, response.FileSizeInBytes); var assetStatusResult = new GetAssetStatusResult { Status = AssetDownloadStatus.InCache, InQueueSince = DateTime.MinValue, EstimatedPreparationDuration = TimeSpan.Zero, EstimatedPreparationEnd = DateTime.Now, FileSizeInBytes = response.FileSizeInBytes }; Log.Information("Constructed getAssetStatusResult"); await context.RespondAsync(assetStatusResult); return; } // Is that asset in the preparation queue? var status = await assetManager.CheckPreparationStatus(message.ArchiveRecordId); if (status.PackageIsInPreparationQueue) { Log.Information("Found the asset for id {ArchiveRecordId} with type {AssetType} in the preparation queue.", message.ArchiveRecordId, message.AssetType); var assetStatusResult = new GetAssetStatusResult { Status = AssetDownloadStatus.InPreparationQueue, InQueueSince = status.AddedToQueueOn, EstimatedPreparationDuration = status.EstimatedPreparationDuration, EstimatedPreparationEnd = status.AddedToQueueOn == DateTime.MinValue ? DateTime.MinValue : status.AddedToQueueOn.AddTicks(status.EstimatedPreparationDuration.Ticks) }; await context.RespondAsync(assetStatusResult); return; } // The asset is not available await context.RespondAsync(new GetAssetStatusResult { Status = AssetDownloadStatus.RequiresPreparation, InQueueSince = DateTime.MinValue, EstimatedPreparationDuration = status.EstimatedPreparationDuration, EstimatedPreparationEnd = status.AddedToQueueOn == DateTime.MinValue ? DateTime.MinValue : status.AddedToQueueOn.AddTicks(status.EstimatedPreparationDuration.Ticks) }); } }
public async Task Consume(ConsumeContext <PrepareAssetRequest> context) { using (LogContext.PushProperty(nameof(context.ConversationId), context.ConversationId)) { Log.Information("Received {CommandName} command with conversationId {ConversationId} from the bus", nameof(PrepareAssetRequest), context.ConversationId); var message = context.Message; // Is that asset in the preparation queue? var status = await assetManager.CheckPreparationStatus(message.ArchiveRecordId); if (status.PackageIsInPreparationQueue) { Log.Information("Found the asset for id {ArchiveRecordId} with type {AssetType} in the preparation queue.", message.ArchiveRecordId, message.AssetType); var prepareAssetResult = new PrepareAssetResult { Status = AssetDownloadStatus.InPreparationQueue, InQueueSince = status.AddedToQueueOn, EstimatedPreparationDuration = status.EstimatedPreparationDuration, EstimatedPreparationEnd = status.AddedToQueueOn.AddTicks(status.EstimatedPreparationDuration.Ticks) }; await context.RespondAsync(prepareAssetResult); return; } // Asset is not in preperation queue, // so we start the process of downloading the package and then transforming it switch (message.AssetType) { case AssetType.Gebrauchskopie: Log.Information("Start fetching usage copy for id {ArchiveRecordId} with type {AssetType}.", message.ArchiveRecordId, message.AssetType); var archiveRecord = await indexClient.Request(new FindArchiveRecordRequest { ArchiveRecordId = message.ArchiveRecordId }); // Register the job in the queue var auftragId = await assetManager.RegisterJobInPreparationQueue(message.ArchiveRecordId, message.AssetId, AufbereitungsArtEnum.Download, AufbereitungsServices.AssetService, archiveRecord.ElasticArchiveRecord.PrimaryData, new DownloadPackage { PackageId = message.AssetId, CallerId = message.CallerId, ArchiveRecordId = message.ArchiveRecordId, RetentionCategory = message.RetentionCategory, Recipient = context.Message.Recipient, DeepLinkToVe = context.Message.DeepLinkToVe }); await context.RespondAsync(new PrepareAssetResult { Status = AssetDownloadStatus.InPreparationQueue, InQueueSince = DateTime.Now, EstimatedPreparationDuration = status.EstimatedPreparationDuration, EstimatedPreparationEnd = status.AddedToQueueOn.AddTicks(status.EstimatedPreparationDuration.Ticks) }); break; case AssetType.Benutzungskopie: throw new ArgumentOutOfRangeException(); default: throw new ArgumentOutOfRangeException(); } } }