Esempio n. 1
0
        public IRpcWorkerChannel Create(string scriptRootPath, string runtime, IMetricsLogger metricsLogger, int attemptCount, IEnumerable <RpcWorkerConfig> workerConfigs)
        {
            var languageWorkerConfig = workerConfigs.Where(c => c.Description.Language.Equals(runtime, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (languageWorkerConfig == null)
            {
                throw new InvalidOperationException($"WorkerCofig for runtime: {runtime} not found");
            }
            string         workerId         = Guid.NewGuid().ToString();
            ILogger        workerLogger     = _loggerFactory.CreateLogger($"Worker.LanguageWorkerChannel.{runtime}.{workerId}");
            IWorkerProcess rpcWorkerProcess = _rpcWorkerProcessFactory.Create(workerId, runtime, scriptRootPath, languageWorkerConfig);

            return(new GrpcWorkerChannel(
                       workerId,
                       _eventManager,
                       languageWorkerConfig,
                       rpcWorkerProcess,
                       workerLogger,
                       metricsLogger,
                       attemptCount,
                       _environment,
                       _applicationHostOptions,
                       _sharedMemoryManager,
                       _functionDataCache,
                       _workerConcurrencyOptions));
        }
Esempio n. 2
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                WorkerDto workerDto = new WorkerDto();
                workerDto.idDivision = int.Parse(tbDivisionID.Text);
                //workerDto.idWorker = int.Parse(tbID.Text);
                workerDto.Name = tbName.Text;
                IWorkerProcess workerProcess = ProcessFactory.GetWorkerProcess();

                if (_id == 0)
                {
                    workerProcess.Add(workerDto);
                }
                else
                {
                    workerDto.idDivision = _id;
                    workerProcess.Update(workerDto);
                }
                this.Close();
            } catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public MessengerServiceFacade()
        {
            //postSorter = postmaster;
            //TODO: Properly instantiate the WorkerProcess

            membershipHandle = new MembershipService();
            profileHandle = new ProfileService();

            postSorter = new WorkerProcess(new MessagingContext("Kalanjiyam"), membershipHandle, profileHandle);
        }
        internal GrpcWorkerChannel(
            string workerId,
            IScriptEventManager eventManager,
            RpcWorkerConfig workerConfig,
            IWorkerProcess rpcWorkerProcess,
            ILogger logger,
            IMetricsLogger metricsLogger,
            int attemptCount,
            IEnvironment environment,
            IOptionsMonitor <ScriptApplicationHostOptions> applicationHostOptions,
            ISharedMemoryManager sharedMemoryManager,
            IFunctionDataCache functionDataCache,
            IOptions <WorkerConcurrencyOptions> workerConcurrencyOptions)
        {
            _workerId                 = workerId;
            _eventManager             = eventManager;
            _workerConfig             = workerConfig;
            _runtime                  = workerConfig.Description.Language;
            _rpcWorkerProcess         = rpcWorkerProcess;
            _workerChannelLogger      = logger;
            _metricsLogger            = metricsLogger;
            _environment              = environment;
            _applicationHostOptions   = applicationHostOptions;
            _sharedMemoryManager      = sharedMemoryManager;
            _workerConcurrencyOptions = workerConcurrencyOptions;

            _workerCapabilities = new GrpcCapabilities(_workerChannelLogger);

            _inboundWorkerEvents = _eventManager.OfType <InboundGrpcEvent>()
                                   .Where(msg => msg.WorkerId == _workerId);

            _eventSubscriptions.Add(_inboundWorkerEvents
                                    .Where(msg => msg.IsMessageOfType(MsgType.RpcLog) && !msg.IsLogOfCategory(RpcLogCategory.System))
                                    .Subscribe(Log));

            _eventSubscriptions.Add(_inboundWorkerEvents
                                    .Where(msg => msg.IsMessageOfType(MsgType.RpcLog) && msg.IsLogOfCategory(RpcLogCategory.System))
                                    .Subscribe(SystemLog));

            _eventSubscriptions.Add(_eventManager.OfType <FileEvent>()
                                    .Where(msg => _workerConfig.Description.Extensions.Contains(Path.GetExtension(msg.FileChangeArguments.FullPath)))
                                    .Throttle(TimeSpan.FromMilliseconds(300)) // debounce
                                    .Subscribe(msg => _eventManager.Publish(new HostRestartEvent())));

            _eventSubscriptions.Add(_inboundWorkerEvents.Where(msg => msg.MessageType == MsgType.InvocationResponse)
                                    .Subscribe(async(msg) => await InvokeResponse(msg.Message.InvocationResponse)));

            _inboundWorkerEvents.Where(msg => msg.MessageType == MsgType.WorkerStatusResponse)
            .Subscribe((msg) => ReceiveWorkerStatusResponse(msg.Message.RequestId, msg.Message.WorkerStatusResponse));

            _startLatencyMetric = metricsLogger?.LatencyEvent(string.Format(MetricEventNames.WorkerInitializeLatency, workerConfig.Description.Language, attemptCount));

            _state = RpcWorkerChannelState.Default;
        }
Esempio n. 5
0
        public IHttpWorkerChannel Create(string scriptRootPath, IMetricsLogger metricsLogger, int attemptCount)
        {
            string         workerId          = Guid.NewGuid().ToString();
            ILogger        workerLogger      = _loggerFactory.CreateLogger($"Worker.HttpWorkerChannel.{workerId}");
            IWorkerProcess httpWorkerProcess = _httpWorkerProcessFactory.Create(workerId, scriptRootPath, _httpWorkerOptions);

            return(new HttpWorkerChannel(
                       workerId,
                       httpWorkerProcess,
                       _httpWorkerService,
                       workerLogger,
                       metricsLogger,
                       attemptCount));
        }
 internal HttpWorkerChannel(
     string workerId,
     IWorkerProcess rpcWorkerProcess,
     IHttpWorkerService httpWorkerService,
     ILogger logger,
     IMetricsLogger metricsLogger,
     int attemptCount)
 {
     Id = workerId;
     _rpcWorkerProcess    = rpcWorkerProcess;
     _workerChannelLogger = logger;
     _httpWorkerService   = httpWorkerService;
     _startLatencyMetric  = metricsLogger?.LatencyEvent(string.Format(MetricEventNames.WorkerInitializeLatency, "HttpWorker", attemptCount));
 }
        internal RpcWorkerChannel(
            string workerId,
            string rootScriptPath,
            IScriptEventManager eventManager,
            RpcWorkerConfig workerConfig,
            IWorkerProcess rpcWorkerProcess,
            ILogger logger,
            IMetricsLogger metricsLogger,
            int attemptCount,
            IOptions <ManagedDependencyOptions> managedDependencyOptions = null)
        {
            _workerId            = workerId;
            _rootScriptPath      = rootScriptPath;
            _eventManager        = eventManager;
            _workerConfig        = workerConfig;
            _runtime             = workerConfig.Description.Language;
            _rpcWorkerProcess    = rpcWorkerProcess;
            _workerChannelLogger = logger;
            _metricsLogger       = metricsLogger;

            _workerCapabilities = new Capabilities(_workerChannelLogger);

            _inboundWorkerEvents = _eventManager.OfType <InboundEvent>()
                                   .Where(msg => msg.WorkerId == _workerId);

            _eventSubscriptions.Add(_inboundWorkerEvents
                                    .Where(msg => msg.IsMessageOfType(MsgType.RpcLog) && !msg.IsLogOfCategory(RpcLogCategory.System))
                                    .Subscribe(Log));

            _eventSubscriptions.Add(_inboundWorkerEvents
                                    .Where(msg => msg.IsMessageOfType(MsgType.RpcLog) && msg.IsLogOfCategory(RpcLogCategory.System))
                                    .Subscribe(SystemLog));

            _eventSubscriptions.Add(_eventManager.OfType <FileEvent>()
                                    .Where(msg => _workerConfig.Description.Extensions.Contains(Path.GetExtension(msg.FileChangeArguments.FullPath)))
                                    .Throttle(TimeSpan.FromMilliseconds(300)) // debounce
                                    .Subscribe(msg => _eventManager.Publish(new HostRestartEvent())));

            _eventSubscriptions.Add(_inboundWorkerEvents.Where(msg => msg.MessageType == MsgType.FunctionLoadResponse)
                                    .Subscribe((msg) => LoadResponse(msg.Message.FunctionLoadResponse)));

            _eventSubscriptions.Add(_inboundWorkerEvents.Where(msg => msg.MessageType == MsgType.InvocationResponse)
                                    .Subscribe((msg) => InvokeResponse(msg.Message.InvocationResponse)));

            _startLatencyMetric       = metricsLogger?.LatencyEvent(string.Format(MetricEventNames.WorkerInitializeLatency, workerConfig.Description.Language, attemptCount));
            _managedDependencyOptions = managedDependencyOptions;

            _state = RpcWorkerChannelState.Default;
        }
        public IRpcWorkerChannel Create(string scriptRootPath, string runtime, IMetricsLogger metricsLogger, int attemptCount, IOptions <ManagedDependencyOptions> managedDependencyOptions = null)
        {
            var languageWorkerConfig = _workerConfigs.Where(c => c.Description.Language.Equals(runtime, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (languageWorkerConfig == null)
            {
                throw new InvalidOperationException($"WorkerCofig for runtime: {runtime} not found");
            }
            string         workerId         = Guid.NewGuid().ToString();
            ILogger        workerLogger     = _loggerFactory.CreateLogger($"Worker.LanguageWorkerChannel.{runtime}.{workerId}");
            IWorkerProcess rpcWorkerProcess = _rpcWorkerProcessFactory.Create(workerId, runtime, scriptRootPath);

            return(new RpcWorkerChannel(
                       workerId,
                       scriptRootPath,
                       _eventManager,
                       languageWorkerConfig,
                       rpcWorkerProcess,
                       workerLogger,
                       metricsLogger,
                       attemptCount,
                       managedDependencyOptions));
        }