Skip to content

Instantly share code, notes, and snippets.

@andrewboudreau
Last active December 17, 2020 04:23
Show Gist options
  • Save andrewboudreau/2bd66a617095599d655a3de17f08f5b2 to your computer and use it in GitHub Desktop.
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?
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