Last active
December 17, 2020 04:23
-
-
Save andrewboudreau/2bd66a617095599d655a3de17f08f5b2 to your computer and use it in GitHub Desktop.
A consumer which updates document related details when a conversion has completed or failed?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PdfConversionCompletedConsumer : | |
IConsumer<PdfConversionCompleted>, | |
IConsumer<Fault<ConvertToPdfCommand>> | |
{ | |
private readonly IDataContext dataContext; | |
public ConversionCompletedEventHandler(IDataContext dataContext) | |
{ | |
this.dataContext = dataContext; | |
} | |
public async Task Consume(ConsumeContext<PdfConversionCompleted> context) | |
{ | |
var document = await dataContext.Documents.FindAsync(context.Message.DocumentId, context.CancellationToken); | |
var conversion = new PdfConversion(context.Message.ContentAccessToken); | |
document.SetPdfConversion(conversion); | |
await dataContext.SaveChangesAsync(context.CancellationToken); | |
} | |
public async Task Consume(ConsumeContext<Fault<ConvertToPdfCommand>> context) | |
{ | |
var document = await dataContext.Documents.FindAsync(context.Message.Message.DocumentId, context.CancellationToken); | |
document.SetPdfConversion(PdfConversion.Errored); | |
await dataContext.SaveChangesAsync(context.CancellationToken); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment