Esempio n. 1
0
        public QueueProcessor(Logger log, IDataStore dataStore, IHubContext<IMatchmakingClient> hub, ITracker tracker, IMatchEvaluator matchBuilder, CircularBuffer<TimeSpan> timeToMatch)
        {
            _log = log;
            _dataStore = dataStore;
            _hub = hub;
            _tracker = tracker;
            _matchBuilder = matchBuilder;
            _timeToMatch = timeToMatch;

            _queueSleepMin = Int32.Parse( CloudConfigurationManager.GetSetting("QueueSleepMin") );
            _queueSleepMax = Int32.Parse( CloudConfigurationManager.GetSetting("QueueSleepMax") );
            _queueSleepLength = Int32.Parse( CloudConfigurationManager.GetSetting("QueueSleepLength") );

            Task.Run( async () =>
            {
                _log.Info("Running QueueProcessor...");

                while( true )
                {
                    var sleepTime = _queueSleepMax;

                    try
                    {
                        await processQueue();
                        sleepTime = _queueSleepMax - (_dataStore.DocumentDbPopulation * (_queueSleepMax/_queueSleepLength));
                    }
                    catch(Exception ex)
                    {
                        _log.Error(ex);
                    }

                    Thread.Sleep(sleepTime < _queueSleepMin ? _queueSleepMin : sleepTime);
                }
            });
        }
        private bool ShouldIncludeMetadata(string logicalName, IMatchEvaluator entitiesToInclude, IMatchEvaluator entitiesToExclude)
        {
            var includeWeight = entitiesToInclude.ScoreMatch(logicalName);
            var excludeWeight = entitiesToExclude.ScoreMatch(logicalName);

            return(includeWeight > excludeWeight);
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a custom match evaluator.
        /// </summary>
        /// <param name="evaluator">The match evaluator instance.</param>
        /// <returns>The filter instance (this).</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="evaluator"/> is null.</exception>
        public IFilter <T> AddEvaluator(IMatchEvaluator evaluator)
        {
            if (evaluator == null)
            {
                throw new ArgumentNullException();
            }

            _comparer.Evaluators.Add(evaluator);
            return(this);
        }