Esempio n. 1
0
        private void InternalStart()
        {
            _logger.LogTrace($"{nameof(MonitorLocalProcess)}: Internal starting local process");

            _localProcess = new LocalProcessBuilder(_localProcessBuilder)
            {
                CaptureOutput = x => _monitorStream.Post(x),
                OnExit        = OnProcessExit
            }
            .Build(_logger)
            .ToSubjectScope();

            _localProcess.Subject.Run((CancellationToken)_token !);
            _monitorStateScope.Set(MonitorState.Started);
        }
Esempio n. 2
0
        public LocalProcess(LocalProcessBuilder builder, ILogger logger)
        {
            builder.VerifyNotNull(nameof(builder));
            logger.VerifyNotNull(nameof(logger));

            _logger           = logger;
            _successExitCode  = builder.SuccessExitCode;
            _executeFile      = builder.ExecuteFile;
            _arguments        = builder.Arguments;
            _workingDirectory = builder.WorkingDirectory;
            _captureOutput    = builder.CaptureOutput;
            _useShellExecute  = builder.UseShellExecute;

            _onExitNotify = builder.OnExit != null ? new SubjectScope <Action>(builder.OnExit) : null;
        }
Esempio n. 3
0
        public Task <bool> Start(CancellationToken token)
        {
            _logger.LogInformation($"{nameof(MonitorLocalProcess)}: Starting the local process monitoring");

            _token ??= token;
            _tokenRegistration ??= token.Register(async() =>
            {
                _logger.LogTrace($"{nameof(MonitorLocalProcess)}: Canceled MonitorLocalProcess");
                await Stop();
            });

            _runningTcs = new TaskCompletionSource <bool>().ToSubjectScope();

            InternalStart();

            return(_runningTcs.Subject.Task);
        }
Esempio n. 4
0
        public Task Start()
        {
            _executionContext.DeploymentFolder.VerifyNotEmpty(nameof(_executionContext.DeploymentFolder));

            _logger.LogInformation($"Starting ML child process, deployment folder={_executionContext.DeploymentFolder}");

            var tcs = new TaskCompletionSource <bool>();

            ModelExecuteDetails modelExecute =
                ReadManifest()
                ?? CheckIfRunExist()
                ?? throw new InvalidOperationException("No support for starting model");

            _localProcess = new LocalProcessBuilder()
            {
                ExecuteFile      = modelExecute.ExecutePath,
                Arguments        = modelExecute.Arguments,
                WorkingDirectory = _executionContext.DeploymentFolder,
                CaptureOutput    = lineData =>
                {
                    switch (lineData)
                    {
                    case string subject when LookFor(subject, modelExecute.StartSignal):
                        _logger.LogInformation($"Detected running command: {lineData}");

                        tcs.SetResult(true);
                        _executionContext.State = ExecutionState.Running;
                        break;

                    case string subject when LookFor(subject, "RuntimeError", "not enough memory"):
                        _logger.LogError($"Detected running runtime error, not enough memory, {lineData}");

                        _executionContext.State = ExecutionState.Failed;
                        break;
                    }
                }
            }