Exemple #1
0
        /// <summary>
        /// Организует цикл по аккаунтам
        /// </summary>
        /// <param name="method"></param>
        public void ForEachAccount(Action <ForEachAccountData> method)
        {
            try
            {
                Logger.Trace("Начинаем обработку всех аккаунтов");
                var client   = DispatcherHelper.GetDispatcherClient();
                var accounts = client.GetAccounts(new GetAccountsRequestData()
                {
                    Status = AccountStatus.Active
                }).Data;

                Logger.Trace("Найдено аккаунтов: " + accounts.Length);
                var tasks = new ThreadTaskQueue(AccountThreads);
                tasks.ForEach(accounts, account =>
                {
                    CancellationToken.ThrowIfCancellationRequested();
                    ForEachAccountWrapper(account, method);
                });
            }
            catch (ThreadAbortException) { }
            catch (OperationCanceledException) { }
            catch (Exception exception)
            {
                SetException(exception);
                Tools.HandleOutOfMemoryException(exception);
                Logger.Error(exception);
            }
            finally
            {
                Logger.Trace("Обработка всех аккаунтов завершена");
            }
        }
Exemple #2
0
        public void ForEachAccountComponents(AccountInfo account, Action <ForEachComponentData> method, bool withDeleted = false)
        {
            try
            {
                Logger.Trace("Начинаем обработку компонентов аккаунта; accountId:{0} accountName:{1}", account.Id, account.DisplayName);
                CancellationToken.ThrowIfCancellationRequested();
                using (var accountDbContext = AccountDbContext.CreateFromDatabaseId(account.AccountDatabaseId))
                {
                    var componentRepository = accountDbContext.GetComponentRepository();
                    var components          = !withDeleted?
                                              componentRepository.QueryAll().ToArray() :
                                                  componentRepository.QueryAllWithDeleted().ToArray();

                    Logger.Trace("Найдено компонентов: " + components.Length);
                    var tasks = new ThreadTaskQueue(ComponentsThreads);
                    tasks.ForEach(components, component =>
                    {
                        CancellationToken.ThrowIfCancellationRequested();
                        ForEachAccountComponentsWrapper(account, component, method);
                    });
                }
            }
            catch (ThreadAbortException) { }
            catch (OperationCanceledException) { }
            catch (Exception exception)
            {
                SetException(exception);
                Tools.HandleOutOfMemoryException(exception);
                Logger.Error(exception);
            }
            finally
            {
                Logger.Trace("Обработка аккаунта завершена; accountId:{0} accountName:{1}", account.Id, account.DisplayName);
            }
        }
        protected void ProcessAccount(
            Guid accountId,
            AccountDbContext accountDbContext,
            ILogger logger,
            string accountName,
            CancellationToken token,
            Guid?unitTestId = null)
        {
            var now            = GetDispatcherClient().GetServerTime().Data.Date;
            var repository     = accountDbContext.GetUnitTestRepository();
            var unitTestTypeId = GetUnitTestTypeId();
            var tests          = repository.GetForProcessing(unitTestTypeId, now);

            if (unitTestId.HasValue)
            {
                tests = tests.Where(t => t.Id == unitTestId.Value).ToList();
            }

            // был баг, когда компонент был выключен, а проверка имела ParentEnable == True
            // в итоге агент каждый раз выполнял проверку, отправлял диспетчеру, а тот ее игнорировал
            // tests = tests.Where(x => x.Component.CanProcess).ToList();

            if (tests.Count == 0)
            {
                logger.Trace("В аккаунте {0} нет проверок для выполнения", accountName);
                return;
            }
            logger.Debug("В аккаунте {0} начинаем выполнять {1} проверок", accountName, tests.Count);
            // для одного аккаунта будет задействовано максимум 20 потоков на все его проверки
            var tasks = new ThreadTaskQueue(20);

            tasks.ForEach(tests, test =>
            {
                Guid testId = test.Id;
                try
                {
                    ProcessUnitTest(accountId, testId, logger, accountName, token);
                }
                catch (OperationCanceledException)
                {
                }
            });

            if (SuccessCount > 0 || ErrorCount > 0)
            {
                logger.Info("Выполнено проверок успешно: {0}, с ошибкой: {1}", SuccessCount, ErrorCount);
            }
        }