Пример #1
0
        /// <summary>
        ///   Waits for process to start.
        /// </summary>
        /// <param name="service">The service to check processes within.</param>
        /// <param name="process">The process to wait for.</param>
        /// <param name="millisTimeout">Timeout giving up the wait.</param>
        /// <returns>The inparam service.</returns>
        public static IContainerService WaitForProcess(this IContainerService service, string process,
                                                       long millisTimeout = -1)
        {
            if (service == null)
            {
                return(null);
            }

            Exception exception = null;
            var       stopwatch = Stopwatch.StartNew();

            using (var mre = new ManualResetEventSlim())
                using (new Timer(_ =>
                {
                    var processes = service.GetRunningProcesses();
                    if (processes?.Rows.Any(x => x.Command == process) ?? false)
                    {
                        mre.Set();
                    }
                    if (stopwatch.ElapsedMilliseconds > millisTimeout)
                    {
                        exception = new FluentDockerException($"Wait expired for process {process} in container {service.Id}");
                        mre.Set();
                    }
                }, null, 0, 500))
                    mre.Wait();

            if (exception != null)
            {
                throw exception;
            }

            return(service);
        }
Пример #2
0
        /// <summary>
        ///   Waits for process to start.
        /// </summary>
        /// <param name="service">The service to check processes within.</param>
        /// <param name="process">The process to wait for.</param>
        /// <param name="millisTimeout">Timeout giving up the wait.</param>
        /// <returns>The inparam service.</returns>
        public static IContainerService WaitForProcess(this IContainerService service, string process,
                                                       long millisTimeout = -1)
        {
            if (null == service)
            {
                return(null);
            }

            do
            {
                var p = service.GetRunningProcesses();
                if (p?.Rows != null && p.Rows.Count > 0)
                {
                    if (p.Rows.Any(x => x.Command == process))
                    {
                        return(service);
                    }
                }

                millisTimeout -= 500;
            } while (millisTimeout > 0);

            throw new FluentDockerException($"Wait expired for process {process} in container {service.Id}");
        }