public RecommendationsController(
            IConfiguration configuration, IQueuedRecommendationStorage storage,
            IRecommendationQueue queue = null, IQueueHandler handler = null,
            ILogger <RecommendationsController> logger = null)
        {
            _storage = storage;
            _queue   = queue is null ? new RecommendationQueue(_storage) : queue;

            if (handler is null)
            {
                var optionsBuilder = new DbContextOptionsBuilder <Database.DatabaseContext>();
                optionsBuilder.UseSqlServer(configuration["DatabaseConnectionString"]);
                _handler = QueueHandler.GetOrCreate(optionsBuilder.Options, configuration, _queue, _storage, logger);
            }
            else
            {
                _handler = handler;
            }
        }
Пример #2
0
        public QueueHandler(DbContextOptions <Database.DatabaseContext> dbContextOptions, IConfiguration configuration, IRecommendationQueue queue, IQueuedRecommendationStorage storage, ILogger logger = null)
        {
            _queue   = queue;
            _storage = storage;
            _logger  = logger;

            var engineOptions = configuration.Get <PythonEngineOptions>();

            _recommendationEngine = new PythonRecommendationEngine(dbContextOptions, engineOptions);
            _runningTasks         = new List <RecommendationTask>(ConcurrentRecommendationsLimit);

            Task.Run(() =>
            {
                while (true)
                {
                    Tick();
                    Thread.Sleep(500);
                }
            });
        }
Пример #3
0
        /// <summary>
        /// Either returns an already created instance or creates a new one. This is needed because mvc controllers are recreated on each request
        /// </summary>
        public static QueueHandler GetOrCreate(DbContextOptions <Database.DatabaseContext> dbContextOptions, IConfiguration configuration, IRecommendationQueue queue, IQueuedRecommendationStorage storage, ILogger logger = null)
        {
            if (_handlerInstance is null)
            {
                _handlerInstance = new QueueHandler(dbContextOptions, configuration, queue, storage, logger);
            }

            return(_handlerInstance);
        }