Beispiel #1
0
        private void _ExecuteCommand(IDBCommand command)
        {
            if (command != null)
            {
                if (command.QueryId != null && _cancelledQueries.Contains(command.QueryId))
                {
                    command.CancelCommand = true;
                }

                //if (command.Blocking)
                //    Interlocked.Decrement(ref blockingCommandsCount);


                try
                {
                    TimeSpan waitInQueueSpanTime = DateTime.Now.Subtract(command.GetQueueInsertionTime());
                    DateTime executionStartTime  = DateTime.Now;

                    //if (!isDummy)
                    //    GeneralLogger.Instance.AddLine(LogMessageType.CommandsQueueBlocking, command, command.Blocking);

                    command.Execute(_dbConnection);

                    // Writing Command DONE message to log
                    TimeSpan executionSpanTime = DateTime.Now.Subtract(executionStartTime);
                    /******************************************/

                    // Queue size exceeded - issuing warning, activating callback
                    if (Count > ct_commandQueueSizeExceededWarningThreshold)
                    {
                        GatLogger.Instance.AddMessage("Commands queue threshold exceeded", LogMode.LogAndScreen);
                    }
                    //GeneralLogger.Instance.AddLine(
                    //    LogMessageType.CommandsQueueNumberOfDBCommandsExceeded,
                    //    commandQueueSizeExceededWarningThreshold, Count);


                    // Command executions per minute
                    DateTime now = DateTime.Now;
                    if (_lastCommandExecutionTime.Minute == now.Minute)
                    {
                        _commandsExecutedInLastMinute++;
                    }
                    else
                    {
                        //GeneralLogger.Instance.AddLine(LogMessageType.CommandsQueueCurrExecutionRate, commandsExecutedInLastMinute);
                        _commandsExecutedInLastMinute = 0;
                    }

                    _lastCommandExecutionTime = now;
                }
                catch (Exception e)
                {
                    s_LogAndThrowException(command, e);
                    command.ErrorEventHandler();
                }
            }
        }
        /// <summary>
        /// Filters and executes the commands until multi queue getting full again and or command is new is queue
        /// </summary>
        private void _FilterAndExecuteCommands(ThreadSafeMultiQueue <string, IDBCommand> multiQueue, CommandPriority currentPriority)
        {
            bool queueTooLoaded = multiQueue.Count() > ct_queueThreshold;

            while (_commandsToExecute.Count > 0)
            {
                if (_GetHighestNonEmptyPriority() < currentPriority)
                {
                    return;
                }

                if (queueTooLoaded)
                {
                    //if filtering process began when queue was too loaded or there is blocking command in queue
                    //all commands that passed in the filter will be executed regardless of
                    //how much time they were in queue
                    _ExecuteCommand(_commandsToExecute.Dequeue());
                }
                else if (_MinimumCommandQueueTime.HasValue)
                {
                    //If commands was not in queue for enough time the execution process is halted
                    IDBCommand nextCommand     = _commandsToExecute.Peek();
                    DateTime   filterThreshold = nextCommand.GetQueueInsertionTime() + _MinimumCommandQueueTime.Value;
                    if (_lastFilterEndTime < filterThreshold)
                    {
                        return;
                    }

                    _ExecuteCommand(_commandsToExecute.Dequeue());
                }
                else
                {
                    throw new GatDataBaseException(
                              "filterAndExecuteCommands was called when queueTooLoaded = false and !parameters.MinimumCommandQueueTime.HasValue");
                }

                //If queue is getting loaded the execution process is halted
                if (multiQueue.Count() >= ct_queueThreshold)
                {
                    return;
                }
            }
        }