public async Task <CompensationResult> Compensate(CompensateContext <GuidLog> context) { _logger.LogWarning("Database initialization failed, re-scheduling original event in 30 seconds."); await _repository.AddAsync(new ScheduledEvent(Guid.NewGuid(), typeof(IDatabaseCreated).AssemblyQualifiedName, "{}", DateTimeOffset.UtcNow.AddSeconds(30))); await _repository.SaveChanges(); _logger.LogInformation("Another attempt to initialize the database will happen in 30 seconds."); return(context.Compensated()); }
public async Task <CompensationResult> Compensate(CompensateContext <GuidLog> context) { var result = await _busPublisher.SendRequest(new DeleteUser { Id = context.Log.Id }); if (!result.Successful) { throw result.ToException(); } await _scheduledEventRepo.AddAsync(new ScheduledEvent(Guid.NewGuid(), typeof(IDatabaseCreated).AssemblyQualifiedName, "{}", DateTimeOffset.UtcNow)); await _scheduledEventRepo.SaveChanges(); return(context.Compensated()); }
protected async Task ScheduleRepeatedRunAsync(ISourceEventData sourceEventData, bool shouldBeDelayed) { var delay = shouldBeDelayed ? _consistencyConfiguration.DelayedRepeatedRunInterval : _consistencyConfiguration.ImmediateRepeatedRunInterval; var scheduledRun = new ScheduledEvent( Guid.NewGuid(), sourceEventData.FullyQualifiedEventTypeName, sourceEventData.EventData, DateTimeOffset.UtcNow.Add(delay) ); await _scheduledEventRepository.AddAsync(scheduledRun); await _scheduledEventRepository.SaveChanges(); }
public async Task HandleAsync(ISaleCreated @event, ICorrelationContext correlationContext) { var @expirationEvent = new SaleConfirmationTimeoutExpired { SaleId = @event.Id }; var scheduledRun = new ScheduledEvent( Guid.NewGuid(), typeof(ISaleConfirmationTimeoutExpired).AssemblyQualifiedName, JsonConvert.SerializeObject(expirationEvent), DateTimeOffset.UtcNow.Add(_consistencyConfiguration.UnconfirmedSaleExpirationInterval) ); await _scheduledEventRepository.AddAsync(scheduledRun); await _scheduledEventRepository.SaveChanges(); }