public void Should_retry_on_exception() { var scheduler = Node.System.GetExtension <SchedulingExtension>() .SchedulingActor; var command = new BoomNowCommand(Guid.NewGuid().ToString()); var executionOptions = new ExecutionOptions(DateTime.UtcNow.AddMilliseconds(100), typeof(ValueChangedSuccessfullyEvent), command.AggregateId); var scheduleCommandExecution = new ScheduleCommandExecution(command, new ScheduleKey("test", "test"), executionOptions); scheduler.Tell(scheduleCommandExecution); Node.Transport.Subscribe <MessageMetadataEnvelop>(TestActor); //job will be retried one time, but aggregate will fail permanently due to error on apply method FishForMessage <MessageMetadataEnvelop>(m => m.Message is JobFailed, TimeSpan.FromSeconds(10)); FishForMessage <MessageMetadataEnvelop>(m => m.Message is JobFailed, TimeSpan.FromSeconds(10)); }
private async Task Schedule(ScheduleCommandExecution message) { ScheduleKey key = message.Key; try { _logger.Debug($"Scheduling job {key} for {message.Options.RunAt}"); var job = QuartzJob.Create(message.Key, message.Command, message.CommandMetadata, message.Options); var trigger = TriggerBuilder.Create() .WithIdentity(job.Key.Name, job.Key.Group) .WithSimpleSchedule(x => x.WithMisfireHandlingInstructionFireNow().WithRepeatCount(0)) .StartAt(message.Options.RunAt) .Build(); var fireTime = await _scheduler.ScheduleJob(job, trigger); var scheduleConfirmation = new CommandExecutionScheduled(message.Command.Id, fireTime.UtcDateTime); Sender.Tell(scheduleConfirmation); _publisher.Publish(scheduleConfirmation, message.CommandMetadata); } catch (Exception e) { _logger.Error(e, "Error while scheduled job {Task}", key); if (e is JobPersistenceException && e.InnerException?.GetType() == typeof(ObjectAlreadyExistsException)) { Sender.Tell(new AlreadyScheduled(key)); } else { Sender.Tell(new Status.Failure(e)); } var fault = Fault.New(message, e, message.Command.ProcessId, typeof(SchedulingActor)); _publisher.Publish(fault, message.CommandMetadata); } }
public Task Handle(FutureEventScheduledEvent message, IMessageMetadata messageMetadata) { var scheduleId = message.Id; var succesEventType = message.Event.GetType(); var description = $"Source {message.SourceName} id={message.SourceId} scheduled future event {message.Event.GetType().Name} id={scheduleId} o n{message.RaiseTime}\r\n"; var scheduleKey = CreateScheduleKey(scheduleId, message.SourceId, message.SourceName, description); var command = new RaiseScheduledDomainEventCommand(message.Id, message.SourceId, Guid.NewGuid().ToString()); var metadata = messageMetadata.CreateChild(command.Id, _schedulingFutureEventProcessEntry); var scheduleEvent = new ScheduleCommandExecution(command, scheduleKey, ExecutionOptions.ForCommand(message.RaiseTime, succesEventType), metadata); return(_schedulerActorRef.Ask <object>(scheduleEvent).ContinueWith(t => { switch (t.Result) { case CommandExecutionScheduled sched: break; case Failure f: { _logger.Error(f.Exception, "Error occured during scheduling event"); break; } default: { _logger.Error("Unexpected message received during scheduling event confirmation wait: {msg}", t.Result); break; } } })); }