public RedisSchedulerManager() { _redis = RedisProvider.GetProvider(); }
private void DoValidate() { var redis = RedisProvider.GetProvider(); IDatabase db = redis.GetDatabase(0); string key = "locker-validate-" + Name; try { Console.WriteLine($"Lock: {key} to keep only one validate process."); while (!db.LockTake(key, 0, TimeSpan.FromMinutes(10))) { Thread.Sleep(1000); } var lockerValue = db.HashGet(ValidateStatusName, Name).ToString(); bool needInitStartRequest = lockerValue != "validate finished"; if (needInitStartRequest) { Console.WriteLine("Start validate ..."); if (_validations != null && _validations.Count > 0) { MailBodyBuilder builder = new MailBodyBuilder(Name, #if !NET_CORE System.Configuration.ConfigurationManager.AppSettings["corporation"] #else "ooodata.com" #endif ); foreach (var validation in _validations) { builder.AddValidateResult(validation.Validate()); } string mailBody = builder.Build(); #if !NET_CORE EmailUtil.Send($"{Name} " + "validation report", _validateReportTo, mailBody); #endif } } else { Console.WriteLine("No need to validate on this process because other process did."); } if (needInitStartRequest) { db.HashSet(ValidateStatusName, Name, "validate finished"); } } catch (Exception e) { Console.WriteLine(e); _logger.Error(e.Message, e); } finally { Console.WriteLine("Release locker."); db.LockRelease(key, 0); } }