예제 #1
0
        public Task StartWorkerProcessAsync()
        {
            _startSubscription = _inboundWorkerEvents.Where(msg => msg.MessageType == MsgType.StartStream)
                                 .Timeout(TimeSpan.FromSeconds(LanguageWorkerConstants.ProcessStartTimeoutSeconds))
                                 .Take(1)
                                 .Subscribe(SendWorkerInitRequest, HandleWorkerError);

            var workerContext = new WorkerContext()
            {
                RequestId        = Guid.NewGuid().ToString(),
                MaxMessageLength = LanguageWorkerConstants.DefaultMaxMessageLengthBytes,
                WorkerId         = _workerId,
                Arguments        = _workerConfig.Arguments,
                WorkingDirectory = _rootScriptPath,
                ServerUri        = _serverUri,
            };

            _process = _processFactory.CreateWorkerProcess(workerContext);
            StartProcess();
            _processRegistry?.Register(_process);

            _state = LanguageWorkerChannelState.Initializing;

            return(Task.CompletedTask);
        }
        internal LanguageWorkerProcess(string runtime,
                                       string workerId,
                                       string rootScriptPath,
                                       Uri serverUri,
                                       WorkerProcessArguments workerProcessArguments,
                                       IScriptEventManager eventManager,
                                       IWorkerProcessFactory processFactory,
                                       IProcessRegistry processRegistry,
                                       ILogger workerProcessLogger,
                                       ILanguageWorkerConsoleLogSource consoleLogSource)
        {
            _runtime             = runtime;
            _workerId            = workerId;
            _processFactory      = processFactory;
            _processRegistry     = processRegistry;
            _workerProcessLogger = workerProcessLogger;
            _consoleLogSource    = consoleLogSource;
            _eventManager        = eventManager;

            var workerContext = new WorkerContext()
            {
                RequestId        = Guid.NewGuid().ToString(),
                MaxMessageLength = LanguageWorkerConstants.DefaultMaxMessageLengthBytes,
                WorkerId         = _workerId,
                Arguments        = workerProcessArguments,
                WorkingDirectory = rootScriptPath,
                ServerUri        = serverUri,
            };

            _process = _processFactory.CreateWorkerProcess(workerContext);
        }
예제 #3
0
        public string GetArguments(WorkerContext context)
        {
            var argumentsBuilder = context.Arguments.ExecutableArguments.Aggregate(new StringBuilder(), MergeArguments);

            if (!string.IsNullOrEmpty(context.Arguments.WorkerPath))
            {
                argumentsBuilder.AppendFormat(" \"{0}\"", context.Arguments.WorkerPath);
            }
            context.Arguments.WorkerArguments.Aggregate(argumentsBuilder, MergeArguments);
            argumentsBuilder.Append(context.GetFormatedArguments());
            return(argumentsBuilder.ToString());
        }
예제 #4
0
        public string GetArguments(WorkerContext context)
        {
            var argumentsBuilder = context.Arguments.ExecutableArguments.Aggregate(new StringBuilder(), MergeArguments);

            if (!string.IsNullOrEmpty(context.Arguments.WorkerPath))
            {
                argumentsBuilder.AppendFormat(" \"{0}\"", context.Arguments.WorkerPath);
            }
            context.Arguments.WorkerArguments.Aggregate(argumentsBuilder, MergeArguments);
            argumentsBuilder.AppendFormat(" --host {0} --port {1} --workerId {2} --requestId {3} --grpcMaxMessageLength {4}",
                                          context.ServerUri.Host, context.ServerUri.Port, context.WorkerId, context.RequestId, context.MaxMessageLength);
            return(argumentsBuilder.ToString());
        }
예제 #5
0
        public virtual Process CreateWorkerProcess(WorkerContext context)
        {
            var startInfo = new ProcessStartInfo(context.Arguments.ExecutablePath)
            {
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                CreateNoWindow         = true,
                UseShellExecute        = false,
                ErrorDialog            = false,
                WorkingDirectory       = context.WorkingDirectory,
                Arguments = GetArguments(context),
            };

            return(new Process {
                StartInfo = startInfo
            });
        }
예제 #6
0
        public void StartWorkerProcess()
        {
            _startSubscription = _inboundWorkerEvents.Where(msg => msg.MessageType == MsgType.StartStream)
                                 .Timeout(processStartTimeout)
                                 .Take(1)
                                 .Subscribe(SendWorkerInitRequest, HandleWorkerError);

            var workerContext = new WorkerContext()
            {
                RequestId        = Guid.NewGuid().ToString(),
                MaxMessageLength = LanguageWorkerConstants.DefaultMaxMessageLengthBytes,
                WorkerId         = _workerId,
                Arguments        = _workerConfig.Arguments,
                WorkingDirectory = _rootScriptPath,
                ServerUri        = _serverUri,
            };

            _process = _processFactory.CreateWorkerProcess(workerContext);
            StartProcess();
            _processRegistry?.Register(_process);
        }