public async Task <bool> HandleAsync(JobContextMessage jobContextMessage, CancellationToken cancellationToken) { var fundingServiceContext = new FundingServiceContext(jobContextMessage); try { using (var childLifeTimeScope = _lifetimeScope.BeginLifetimeScope()) { // Get logger ExecutionContext executionContext = (ExecutionContext)childLifeTimeScope.Resolve <IExecutionContext>(); executionContext.JobId = jobContextMessage.JobId.ToString(); _logger.LogDebug("Started Funding Calc Service"); var preFundingSfOrchestrationService = childLifeTimeScope.Resolve <IFundingOrchestrationService>(); // Call logic asynchronously, and return on initial context (no .ConfigureAwait(false)) await preFundingSfOrchestrationService.ExecuteAsync(fundingServiceContext, cancellationToken); _logger.LogDebug("Completed Funding Calc Service"); } ServiceEventSource.Current.ServiceMessage(_context, "Completed Funding Calc Service"); return(true); } catch (OutOfMemoryException oom) { Environment.FailFast("Funding Service Out Of Memory", oom); throw; } catch (Exception ex) { ServiceEventSource.Current.ServiceMessage(_context, "Exception-{0}", ex.ToString()); throw; } }
public EmployerChangedProviderPriorityHandler(IActorProxyFactory proxyFactory, IPaymentLogger paymentLogger, IExecutionContext executionContext) { this.proxyFactory = proxyFactory ?? new ActorProxyFactory(); this.paymentLogger = paymentLogger; this.executionContext = (ESFA.DC.Logging.ExecutionContext)executionContext; }
protected EarningEventHandlerBase(IApprenticeshipKeyService apprenticeshipKeyService, IActorProxyFactory proxyFactory, IPaymentLogger paymentLogger, IExecutionContext executionContext) { this.apprenticeshipKeyService = apprenticeshipKeyService; this.proxyFactory = proxyFactory ?? new ActorProxyFactory(); this.paymentLogger = paymentLogger; this.executionContext = (ESFA.DC.Logging.ExecutionContext)executionContext; }
public CalculatedRequiredLevyAmountHandler(IActorProxyFactory proxyFactory, IPaymentLogger paymentLogger, IExecutionContext executionContext, ILevyMessageRoutingService levyMessageRoutingService) { this.proxyFactory = proxyFactory ?? new ActorProxyFactory(); this.paymentLogger = paymentLogger; this.levyMessageRoutingService = levyMessageRoutingService ?? throw new ArgumentNullException(nameof(levyMessageRoutingService)); this.executionContext = (ESFA.DC.Logging.ExecutionContext)executionContext; }
public void SetUp() { _proxyFactory = new Mock <IActorProxyFactory>(); _levyFundingSourceRepository = new Mock <ILevyFundingSourceRepository>(); _levyMessageRoutingService = new Mock <ILevyMessageRoutingService>(); var executionContext = new ESFA.DC.Logging.ExecutionContext(); _eventHandler = new TestSubmissionEventHandler(_proxyFactory.Object, _levyFundingSourceRepository.Object, Mock.Of <IPaymentLogger>(), executionContext, _levyMessageRoutingService.Object); _event = new SubmissionFailedEvent { Ukprn = 12344325 }; }
private FM35Global RunFunding(FundingDto actorModel, CancellationToken cancellationToken) { if (ExecutionContext is ExecutionContext executionContextObj) { executionContextObj.JobId = "-1"; executionContextObj.TaskKey = ActorId.ToString(); } ILogger logger = LifetimeScope.Resolve <ILogger>(); IExternalDataCache externalDataCache; FM35Global results; try { logger.LogDebug($"{nameof(FM35Actor)} {ActorId} {GC.GetGeneration(actorModel)} starting"); externalDataCache = BuildExternalDataCache(actorModel.ExternalDataCache); logger.LogDebug($"{nameof(FM35Actor)} {ActorId} {GC.GetGeneration(actorModel)} finished getting input data"); cancellationToken.ThrowIfCancellationRequested(); } catch (Exception ex) { ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString()); logger.LogError($"Error while processing {nameof(FM35Actor)}", ex); throw; } using (var childLifetimeScope = LifetimeScope.BeginLifetimeScope(c => { c.RegisterInstance(externalDataCache).As <IExternalDataCache>(); })) { ExecutionContext executionContext = (ExecutionContext)childLifetimeScope.Resolve <IExecutionContext>(); executionContext.JobId = actorModel.JobId.ToString(); executionContext.TaskKey = ActorId.ToString(); ILogger jobLogger = childLifetimeScope.Resolve <ILogger>(); try { jobLogger.LogDebug($"{nameof(FM35Actor)} {ActorId} {GC.GetGeneration(actorModel)} started processing"); IFundingService <FM35LearnerDto, FM35Global> fundingService = childLifetimeScope.Resolve <IFundingService <FM35LearnerDto, FM35Global> >(); var learners = BuildLearners <FM35LearnerDto>(actorModel.ValidLearners); results = fundingService.ProcessFunding(actorModel.UKPRN, learners, cancellationToken); jobLogger.LogDebug($"{nameof(FM35Actor)} {ActorId} {GC.GetGeneration(actorModel)} completed processing"); } catch (Exception ex) { ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString()); jobLogger.LogError($"Error while processing {nameof(FM35Actor)}", ex); throw; } } externalDataCache = null; return(results); }
private async Task <IEnumerable <IValidationError> > RunValidation(ValidationActorModel actorModel, CancellationToken cancellationToken) { if (_executionContext is ExecutionContext executionContextObj) { executionContextObj.JobId = "-1"; executionContextObj.TaskKey = _actorId.ToString(); } ILogger logger = _parentLifeTimeScope.Resolve <ILogger>(); InternalDataCache internalDataCache; ExternalDataCache externalDataCache; FileDataCache fileDataCache; Message message; ValidationContext validationContext; IEnumerable <IValidationError> errors; try { logger.LogDebug($"{nameof(ValidationActor)} {_actorId} {GC.GetGeneration(actorModel)} starting"); internalDataCache = _jsonSerializationService.Deserialize <InternalDataCache>(Encoding.UTF8.GetString(actorModel.InternalDataCache)); externalDataCache = _jsonSerializationService.Deserialize <ExternalDataCache>(Encoding.UTF8.GetString(actorModel.ExternalDataCache)); fileDataCache = _jsonSerializationService.Deserialize <FileDataCache>(Encoding.UTF8.GetString(actorModel.FileDataCache)); message = _jsonSerializationService.Deserialize <Message>(new MemoryStream(actorModel.Message)); validationContext = new ValidationContext { Input = message }; logger.LogDebug($"{nameof(ValidationActor)} {_actorId} {GC.GetGeneration(actorModel)} finished getting input data"); cancellationToken.ThrowIfCancellationRequested(); } catch (Exception ex) { ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString()); logger.LogError($"Error while processing {nameof(ValidationActor)}", ex); throw; } using (var childLifeTimeScope = _parentLifeTimeScope.BeginLifetimeScope(c => { c.RegisterInstance(validationContext).As <IValidationContext>(); c.RegisterInstance(new Cache <IMessage> { Item = message }).As <ICache <IMessage> >(); c.RegisterInstance(internalDataCache).As <IInternalDataCache>(); c.RegisterInstance(externalDataCache).As <IExternalDataCache>(); c.RegisterInstance(fileDataCache).As <IFileDataCache>(); })) { ExecutionContext executionContext = (ExecutionContext)childLifeTimeScope.Resolve <IExecutionContext>(); executionContext.JobId = actorModel.JobId; executionContext.TaskKey = _actorId.ToString(); ILogger jobLogger = childLifeTimeScope.Resolve <ILogger>(); try { jobLogger.LogDebug($"{nameof(ValidationActor)} {_actorId} {GC.GetGeneration(actorModel)} {executionContext.TaskKey} started learners: {validationContext.Input.Learners.Count}"); IRuleSetOrchestrationService <ILearner, IValidationError> preValidationOrchestrationService = childLifeTimeScope .Resolve <IRuleSetOrchestrationService <ILearner, IValidationError> >(); errors = await preValidationOrchestrationService.Execute(cancellationToken); jobLogger.LogDebug($"{nameof(ValidationActor)} {_actorId} {GC.GetGeneration(actorModel)} {executionContext.TaskKey} validation done"); } catch (Exception ex) { ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString()); jobLogger.LogError($"Error while processing {nameof(ValidationActor)}", ex); throw; } } internalDataCache = null; externalDataCache = null; fileDataCache = null; message = null; validationContext = null; return(errors); }
private async Task <IEnumerable <IValidationError> > RunValidation(ValidationActorModel actorModel, CancellationToken cancellationToken) { if (_executionContext is ExecutionContext executionContextObj) { executionContextObj.JobId = "-1"; executionContextObj.TaskKey = _actorId.ToString(); } ILogger logger = _parentLifeTimeScope.Resolve <ILogger>(); InternalDataCache internalDataCache; ExternalDataCache externalDataCacheGet; ExternalDataCache externalDataCache; FileDataCache fileDataCache; Message message; IEnumerable <string> tasks; ValidationContext validationContext; IEnumerable <IValidationError> errors; try { logger.LogDebug($"{nameof(ValidationActor)} {_actorId} {GC.GetGeneration(actorModel)} starting"); internalDataCache = _jsonSerializationService.Deserialize <InternalDataCache>(actorModel.InternalDataCache); externalDataCacheGet = _jsonSerializationService.Deserialize <ExternalDataCache>(actorModel.ExternalDataCache); fileDataCache = _jsonSerializationService.Deserialize <FileDataCache>(actorModel.FileDataCache); message = _jsonSerializationService.Deserialize <Message>(actorModel.Message); tasks = _jsonSerializationService.Deserialize <IEnumerable <string> >(actorModel.TaskList); externalDataCache = new ExternalDataCache { LearningDeliveries = externalDataCacheGet.LearningDeliveries.ToCaseInsensitiveDictionary(), EPAOrganisations = externalDataCacheGet.EPAOrganisations.ToCaseInsensitiveDictionary(), ERNs = externalDataCacheGet.ERNs, FCSContractAllocations = externalDataCacheGet.FCSContractAllocations, Frameworks = externalDataCacheGet.Frameworks, Organisations = externalDataCacheGet.Organisations, Postcodes = externalDataCacheGet.Postcodes.ToCaseInsensitiveHashSet(), ONSPostcodes = externalDataCacheGet.ONSPostcodes, Standards = externalDataCacheGet.Standards, StandardValidities = externalDataCacheGet.StandardValidities, ULNs = externalDataCacheGet.ULNs, ValidationErrors = externalDataCacheGet.ValidationErrors.ToCaseInsensitiveDictionary(), CampusIdentifiers = externalDataCacheGet.CampusIdentifiers }; validationContext = new ValidationContext { Input = message }; logger.LogDebug($"{nameof(ValidationActor)} {_actorId} {GC.GetGeneration(actorModel)} finished getting input data"); cancellationToken.ThrowIfCancellationRequested(); } catch (Exception ex) { ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString()); logger.LogError($"Error while processing {nameof(ValidationActor)}", ex); throw; } using (var childLifeTimeScope = _parentLifeTimeScope.BeginLifetimeScope(c => { c.RegisterInstance(validationContext).As <IValidationContext>(); c.RegisterInstance(new Cache <IMessage> { Item = message }).As <ICache <IMessage> >(); c.RegisterInstance(internalDataCache).As <IInternalDataCache>(); c.RegisterInstance(externalDataCache).As <IExternalDataCache>(); c.RegisterInstance(fileDataCache).As <IFileDataCache>(); })) { ExecutionContext executionContext = (ExecutionContext)childLifeTimeScope.Resolve <IExecutionContext>(); executionContext.JobId = actorModel.JobId; executionContext.TaskKey = _actorId.ToString(); ILogger jobLogger = childLifeTimeScope.Resolve <ILogger>(); try { jobLogger.LogDebug($"{nameof(ValidationActor)} {_actorId} {GC.GetGeneration(actorModel)} {executionContext.TaskKey} started learners: {validationContext.Input.Learners.Count}"); IRuleSetOrchestrationService <ILearner, IValidationError> preValidationOrchestrationService = childLifeTimeScope .Resolve <IRuleSetOrchestrationService <ILearner, IValidationError> >(); errors = await preValidationOrchestrationService.ExecuteAsync(tasks, cancellationToken); jobLogger.LogDebug($"{nameof(ValidationActor)} {_actorId} {GC.GetGeneration(actorModel)} {executionContext.TaskKey} validation done"); } catch (Exception ex) { ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString()); jobLogger.LogError($"Error while processing {nameof(ValidationActor)}", ex); throw; } } internalDataCache = null; externalDataCache = null; fileDataCache = null; message = null; validationContext = null; return(errors); }
private async Task <IEnumerable <IValidationError> > RunValidation(ValidationDPActorModel actorModel, CancellationToken cancellationToken) { if (_executionContext is ExecutionContext executionContextObj) { executionContextObj.JobId = "-1"; executionContextObj.TaskKey = _actorId.ToString(); } ILogger logger = _parentLifeTimeScope.Resolve <ILogger>(); InternalDataCache internalDataCache; ExternalDataCache externalDataCacheGet; ExternalDataCache externalDataCache; FileDataCache fileDataCache; Message message; IEnumerable <IValidationError> errors; try { logger.LogDebug($"{nameof(ValidationDPActor)} {_actorId} {GC.GetGeneration(actorModel)} starting"); internalDataCache = _jsonSerializationService.Deserialize <InternalDataCache>(actorModel.InternalDataCache); externalDataCacheGet = _jsonSerializationService.Deserialize <ExternalDataCache>(actorModel.ExternalDataCache); fileDataCache = _jsonSerializationService.Deserialize <FileDataCache>(actorModel.FileDataCache); message = _jsonSerializationService.Deserialize <Message>(actorModel.Message); externalDataCache = new ExternalDataCache { ULNs = externalDataCacheGet.ULNs, ValidationErrors = externalDataCacheGet.ValidationErrors.ToCaseInsensitiveDictionary(), ValidationRules = externalDataCacheGet.ValidationRules, ReturnPeriod = externalDataCacheGet.ReturnPeriod }; logger.LogDebug($"{nameof(ValidationDPActor)} {_actorId} {GC.GetGeneration(actorModel)} finished getting input data"); cancellationToken.ThrowIfCancellationRequested(); } catch (Exception ex) { ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString()); logger.LogError($"Error while processing {nameof(ValidationDPActor)}", ex); throw; } using (var childLifeTimeScope = _parentLifeTimeScope.BeginLifetimeScope(c => { c.RegisterInstance(new Cache <IMessage> { Item = message }).As <ICache <IMessage> >(); c.RegisterInstance(internalDataCache).As <IInternalDataCache>(); c.RegisterInstance(externalDataCache).As <IExternalDataCache>(); c.RegisterInstance(fileDataCache).As <IFileDataCache>(); })) { ExecutionContext executionContext = (ExecutionContext)childLifeTimeScope.Resolve <IExecutionContext>(); executionContext.JobId = actorModel.JobId; executionContext.TaskKey = _actorId.ToString(); ILogger jobLogger = childLifeTimeScope.Resolve <ILogger>(); try { jobLogger.LogDebug($"{nameof(ValidationDPActor)} {_actorId} {GC.GetGeneration(actorModel)} {executionContext.TaskKey} started Destination and Progressions: {message.LearnerDestinationAndProgressions.Count}"); IRuleSetOrchestrationService <IRule <ILearnerDestinationAndProgression>, ILearnerDestinationAndProgression> preValidationOrchestrationService = childLifeTimeScope .Resolve <IRuleSetOrchestrationService <IRule <ILearnerDestinationAndProgression>, ILearnerDestinationAndProgression> >(); errors = await preValidationOrchestrationService.ExecuteAsync(message.LearnerDestinationAndProgressions, cancellationToken); jobLogger.LogDebug($"{nameof(ValidationDPActor)} {_actorId} {GC.GetGeneration(actorModel)} {executionContext.TaskKey} Destination and Progression validation done"); } catch (Exception ex) { ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString()); jobLogger.LogError($"Error while processing {nameof(ValidationDPActor)}", ex); throw; } } internalDataCache = null; externalDataCache = null; fileDataCache = null; message = null; return(errors); }
private FM25Global RunFunding(FundingDto actorModel, CancellationToken cancellationToken) { if (ExecutionContext is ExecutionContext executionContextObj) { executionContextObj.JobId = "-1"; executionContextObj.TaskKey = ActorId.ToString(); } ILogger logger = LifetimeScope.Resolve <ILogger>(); IExternalDataCache externalDataCache; FM25Global condensedResults; try { logger.LogDebug($"{nameof(FM25Actor)} {ActorId} starting"); externalDataCache = BuildExternalDataCache(actorModel.ExternalDataCache); logger.LogDebug($"{nameof(FM25Actor)} {ActorId} finished getting input data"); cancellationToken.ThrowIfCancellationRequested(); } catch (Exception ex) { ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString()); logger.LogError($"Error while processing {nameof(FM25Actor)}", ex); throw; } using (var childLifetimeScope = LifetimeScope.BeginLifetimeScope(c => { c.RegisterInstance(externalDataCache).As <IExternalDataCache>(); })) { ExecutionContext executionContext = (ExecutionContext)childLifetimeScope.Resolve <IExecutionContext>(); executionContext.JobId = actorModel.JobId.ToString(); executionContext.TaskKey = ActorId.ToString(); ILogger jobLogger = childLifetimeScope.Resolve <ILogger>(); try { jobLogger.LogDebug($"{nameof(FM25Actor)} {ActorId} {GC.GetGeneration(actorModel)} started processing"); IEnumerable <FM25Global> fm25Results; IEnumerable <PeriodisationGlobal> fm25PeriodisationResults; using (var fundingServiceLifetimeScope = childLifetimeScope.BeginLifetimeScope(c => { c.RegisterInstance(new FM25RulebaseProvider()).As <IRulebaseStreamProvider <FM25LearnerDto> >(); })) { jobLogger.LogDebug("FM25 Rulebase Starting"); IFundingService <FM25LearnerDto, IEnumerable <FM25Global> > fundingService = fundingServiceLifetimeScope.Resolve <IFundingService <FM25LearnerDto, IEnumerable <FM25Global> > >(); var learners = BuildLearners <FM25LearnerDto>(actorModel.ValidLearners); fm25Results = fundingService.ProcessFunding(actorModel.UKPRN, learners, cancellationToken).ToList(); jobLogger.LogDebug("FM25 Rulebase Finishing"); } using (var fundingServiceLifetimeScope = childLifetimeScope.BeginLifetimeScope(c => { c.RegisterInstance(new FM25PeriodisationRulebaseProvider()).As <IRulebaseStreamProvider <FM25Global> >(); })) { jobLogger.LogDebug("FM25 Periodisation Rulebase Starting"); IFundingService <FM25Global, IEnumerable <PeriodisationGlobal> > periodisationService = fundingServiceLifetimeScope.Resolve <IFundingService <FM25Global, IEnumerable <PeriodisationGlobal> > >(); fm25PeriodisationResults = periodisationService.ProcessFunding(actorModel.UKPRN, fm25Results, cancellationToken).ToList(); jobLogger.LogDebug("FM25 Periodisation Rulebase Finishing"); IFM25FundingOutputCondenserService <FM25Global, PeriodisationGlobal> condenser = fundingServiceLifetimeScope.Resolve <IFM25FundingOutputCondenserService <FM25Global, PeriodisationGlobal> >(); condensedResults = condenser.CondensePeriodisationResults(fm25Results, fm25PeriodisationResults); } jobLogger.LogDebug($"{nameof(FM25Actor)} {ActorId} {GC.GetGeneration(actorModel)} completed processing"); } catch (Exception ex) { ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString()); jobLogger.LogError($"Error while processing {nameof(FM25Actor)}", ex); throw; } } externalDataCache = null; return(condensedResults); }