public IDistributedMessageSubscriber GetSubscriber(CancellationToken token, ILogger logger, string channelName = null) { var ch = channelName ?? PubChannel; UdpVirtualSubscriber virtualSubscriber = new UdpVirtualSubscriber((s) => { lock (_lock) { _activeSubscribers.Remove(s); _systemLogger.Trace("UDP PubSub channel {channel} removed", s.Channel); if (_activeSubscribers.Count == 0) { _portSubscriber?.Dispose(); _portSubscriber = null; _systemLogger.Info("UDP PubSub UDP listener closed due to empty subscribers"); } } }, ch); lock (_lock) { _activeSubscribers.Add(virtualSubscriber); if (_portSubscriber == null) { _portSubscriber = new UdpPortSubscriber(_ip, _port, _systemLogger, OnUdpMessage); } _portSubscriber.StartIfNot(); } return(virtualSubscriber); }
public async Task Start() { if (!ValidateEnvironment()) { return; } _dashboardService = new DashboardService(PubSubFactory, _logger, _storage, _stateManager, this); await _leaderManager.RunTaskWhenMutexAcquired(_cancellationToken).ContinueWith(r => { _logger.Trace("LeaderSelector complete"); }); // .Wait(_cancellationToken); _taskExecutorsRepo.Start(_cancellationToken); _taskProducer.Start(_cancellationToken); //_watchDog.Start(_cancellationToken);//todo. run on leader node only _dashboardService.Start(_cancellationToken); }
//void InvokeProcessCompletion(ProcessExecutionContext context, bool isFailed) //{ // var process = _registeredProcesses.GetRegisteredProcesses().FirstOrDefault(p => p.ProcessKey == context.ProcessState.ProcessKey); // process?.InvokeProcessCompeteEvent(context, isFailed); // var subscribers = _batchEngineSubscribers.GetProcessSubscribers().Where(p=>p.ProcessKey==context.ProcessState.ProcessKey); // //ProcessRetryContext ct =new ProcessRetryContext(context.ProcessState.Id, context.ProcessState.ProcessKey, context.Logger); // ProcessCompleteContext ct = new ProcessCompleteContext(context.ProcessState.Id, context.ProcessState.ProcessKey, false, false, context.Logger); // //IProcessCompleteContext ctx=new proccom // foreach (var subscriber in subscribers) // { // subscriber.OnProcessComplete(ct); // } //} void Execute(ProcessExecutionContext context) { _logger.Trace(context.GetFormattedLogMessage("Volume request received")); _pauseHandler.WaitOne(); var processKey = context.Configuration.ProcessKey; var processId = context.ProcessState.ProcessId; Pipeline <ProcessExecutionContext> pipeline; var process = _registeredProcesses.GetRegisteredProcesses().FirstOrDefault(p => p.ProcessKey == processKey); try { pipeline = GetPipeline(processId); } catch (Exception e)//todo what to do in-case of FrameworkException { if (_token.IsCancellationRequested) { _logger.Warn("Volume generation cancelled"); return; } pipeline = null; var error = context.GetFormattedLogMessage($"Failed to build process pipeline with message {e.Message}", e); _logger.Error(error, e); HandleError(context, error); return; } if (pipeline == null) { if (_token.IsCancellationRequested) { _logger.Warn("Volume generation cancelled"); return; } var error = context.GetFormattedLogMessage("Volume handler not found"); _logger.Error(error); HandleError(context, error); //context.MarkAsError(_stateManager, error, _registeredProcesses, _batchEngineSubscribers, _logger); ////InvokeProcessCompletion(context, true); //_eventAggregator.PublishAsync(this, Constants.EventProcessFinished, context.ProcessState.Id.ToString());//todo check do we need it //_eventAggregator.PublishAsync(this, Constants.EventCheckGroupCommand, context.ProcessState.GroupId.ToString()); return; } _logger.Trace(context.GetFormattedLogMessage("Volume request sending to pipeline")); try { pipeline.Invoke(context); } catch (Exception e) //todo what to do in-case of FrameworkException { if (_token.IsCancellationRequested) { _logger.Warn("Volume generation cancelled"); return; } var error = context.GetFormattedLogMessage("Error generating volume", e); _logger.Error(error); HandleError(context, error); //context.MarkAsError(_stateManager, error, _registeredProcesses, _batchEngineSubscribers, _logger); //InvokeProcessCompletion(context, true); //_eventAggregator.PublishAsync(this, Constants.EventProcessFinished, context.ProcessState.Id.ToString());//todo check do we need it //_eventAggregator.PublishAsync(this, Constants.EventCheckGroupCommand, context.ProcessState.GroupId.ToString()); } //var t = typeof(GenericProcessHandler<>); //var gType = t.MakeGenericType(processInstance.VolumeDataType); //var handler = Activator.CreateInstance(gType, processInstance, context); ////update start date //if( processInstance.VolumeDataType == typeof(int)) //{ // var pr = GenericProcessHandler.Create(processInstance); // //send to query pipeline // IBaseProcess<int> p = (IBaseProcess<int>)processInstance; // Bus.Instance.QueryAction(()=> p.GetVolume(context), HandleVolume) //IEnumerable<int> // ; //} //else //{ // //todo //} }