public IMessageWaiter <IExpectedCommandExecutor> NewCommandWaiter(TimeSpan?defaultTimeout = null, bool failOnAnyFault = true) { return(_waiterFactory.NewCommandWaiter(defaultTimeout ?? DefaultTimeout, failOnAnyFault)); }
private void ProcessCommand(ICommand command, JobDataMap jobDataMap, IMessageMetadata metadata, JobKey jobKey) { var key = GetScheduleKey(jobDataMap); var options = GetExecutionOptions(jobDataMap, jobKey.Name); if (options.SuccesEventType == null) { throw new Exception("options do not have SuccessEventType for key " + key); } Predicate <object> isExpected = (o => true); //we should work with legacy jobs having only ExecutionOptions, not ExtendedExecutionOptions var extendedOptions = options as ExtendedExecutionOptions; if (!string.IsNullOrEmpty(extendedOptions?.MessageIdFieldName)) { isExpected = o => { var envelop = o as IMessageMetadataEnvelop; if (envelop != null) { o = envelop.Message; } //received fault instead of expected message var type = o?.GetType(); var guid = type?.GetProperty(extendedOptions.MessageIdFieldName)? .GetValue(o); return(guid != null && (Guid)guid == extendedOptions.SuccessMessageId); }; } var commandMetadata = metadata.CreateChild(command.Id, new ProcessEntry(nameof(QuartzJob), PassingCommandToExecutor, CommandRaiseTimeCame)); var task = _executor.NewCommandWaiter(options.Timeout) .Expect(options.SuccesEventType, o => isExpected(o)) .Create() .Execute(command, commandMetadata); if (!task.Wait(options.Timeout)) { throw new ScheduledCommandWasNotConfirmedException(command); } _quartzLogger.LogSuccess(jobKey.Name); var successMetadata = commandMetadata.CreateChild(Guid.NewGuid(), new ProcessEntry(nameof(QuartzJob), "Publishing success notification", "Job execution completed succesfully. Command executed and confirmed.")); var jobSucceeded = new JobSucceeded(jobKey.Name, jobKey.Group, command); _publisher.Publish(jobSucceeded, successMetadata); }