Пример #1
0
 public List <IDaemon> GetList(DaemonType type)
 {
     return(daemons
            .Select(d => d.Value)
            .Where(d => d.Type == type)
            .ToList());
 }
Пример #2
0
 public void Run(DaemonType type, int count)
 {
     for (var i = 0; i < count; i++)
     {
         var daemon = daemonFactory.New(type);
         daemon.Run();
         daemons[daemon.Id] = daemon;
     }
 }
Пример #3
0
        public IDaemon New(DaemonType type)
        {
            switch (type)
            {
            case DaemonType.Parser:
                return(new ParserDaemon(queueApi, sitesApi));

            case DaemonType.Analyzer:
                return(new AnalyzerDaemon(queueApi, sitesApi, analyzerProviders));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Пример #4
0
        public async Task Stop(DaemonType type, int count)
        {
            var s = 0;

            //Удаляем сначала простаивающих демонов
            foreach (var daemon in daemons)
            {
                var d = daemon.Value;
                if (d.Type != type)
                {
                    continue;
                }

                if (s >= count)
                {
                    return;
                }

                if (d.Status == DaemonConstants.IdleStatus)
                {
                    await d.Stop();

                    daemons.Remove(d.Id, out _);
                    ++s;
                }
            }

            foreach (var daemon in daemons)
            {
                var d = daemon.Value;
                if (d.Type != type)
                {
                    continue;
                }

                if (s >= count)
                {
                    return;
                }

                await d.Stop();

                daemons.Remove(d.Id, out _);
                ++s;
            }
        }
        public async Task <object> StopDaemon([FromRoute] DaemonType type)
        {
            await daemonsApi.Stop(type, 1);

            return(true);
        }
 public object RunDaemon([FromRoute] DaemonType type)
 {
     daemonsApi.Run(type, 1);
     return(true);
 }