Beispiel #1
0
        private void Check(string token)
        {
            // 判定一下时间
            using (var serviceScope = _serviceProvider.CreateScope())
            {
                var watchDagServerContext = serviceScope.ServiceProvider.GetService <WatchDagServerContext>();

                var registerContext = watchDagServerContext !.RegisterContext.FirstOrDefault(temp => temp.Token == token);
                if (registerContext == null)
                {
                    return;
                }

                // 如果当前时间大于最后注册时间的 DelayTime 那么加一
                var delayTime = TimeSpan.FromSeconds(registerContext.DelaySecond);
                if (DateTimeOffset.Now - registerContext.LastRegisterTime > delayTime)
                {
                    registerContext.CurrentDelayCount++;
                    watchDagServerContext.SaveChanges();

                    if (registerContext.CurrentDelayCount > registerContext.MaxDelayCount)
                    {
                        // 咬人
                        _logger.LogError($"{registerContext.Token}已经很久没喂狗了");
                    }
                }

                // 再次注册回去
                AddWatch(registerContext);
            }
        }