public void StopThread() { DatabaseOptionBase.UnAssignWorkerFromAllAssigned(DatabaseWorker, _mongoConnection); DatabaseWorker.Delete(_mongoConnection); DatabaseWorker = null; }
private void SetLastWorkTime() { if (_lastUpdatedLastWorkTime + _updateLastWorkTimeMinimumInterval > Clock.Now) { return; } DatabaseWorker.LastWorkTime = Clock.Now; DatabaseWorker.Update(_mongoConnection); }
private List <DatabaseWorker> GetDeadWorkers() { DateTime lastAcceptableWorkerTime = Clock.Now - _timeToWaitForWorkers; List <DatabaseWorker> deadWorkers = DatabaseWorker.GetDeadWorkers(_connection, lastAcceptableWorkerTime); deadWorkers = deadWorkers.Where(worker => _threadHolders.Any(threadHolder => threadHolder.DatabaseWorker.Id == worker.Id) == false).ToList(); return(deadWorkers); }
public ThreadHolder(MongoConnection mongoConnection, OptionStatus optionStatus) { _mongoConnection = mongoConnection; DatabaseWorker = new DatabaseWorker(); DatabaseWorker.Create(_mongoConnection); _lastUpdatedLastWorkTime = Clock.Now; _optionFinder = new OptionFinder(_mongoConnection); _optionStatus = optionStatus; _optionDecider = new OptionDecider(_mongoConnection, _optionStatus); }
public List <OptionBase> Find(DatabaseWorker worker) { List <OptionBase> options = new List <OptionBase>(); List <DatabaseOptionBase> databaseOptions; if (worker == null) { databaseOptions = _databaseOptionFinder.Find(); } else { databaseOptions = _databaseOptionFinder.Find(worker); } List <Type> optionTypes = ReflectionHelper.GetChildTypes(typeof(OptionBase)); foreach (DatabaseOptionBase databaseOption in databaseOptions) { string optionName = databaseOption.GetType().Name; Type optionType = optionTypes.SingleOrDefault(type => type.Name == optionName); if (optionType == null) { Log.Write(_connection, $"Unknown option type {optionType}", typeof(OptionFinder), DataLayer.MongoData.Config.LogLevelEnum.OptionError); continue; } OptionBase option = (OptionBase)Activator.CreateInstance(optionType, _connection, databaseOption); options.Add(option); } return(options); }