private static async Task RestartStagnatedMiners() { var restartGroups = MinerApiWatchdog.GetTimedoutGroups(DateTime.UtcNow); if (restartGroups == null) { return; } await _semaphore.WaitAsync(); try { var miningLocation = StratumService.SelectedServiceLocation; foreach (var groupKey in restartGroups) { if (_runningMiners.ContainsKey(groupKey) == false) { continue; } Logger.Info(Tag, $"Restarting miner group='{groupKey}' API timestamp exceeded"); await _runningMiners[groupKey].StopTask(); await _runningMiners[groupKey].StartTask(miningLocation, _username); } } finally { _semaphore.Release(); } }
// TODO this can be moved in MinerApiWatchdog private void UpdateApiTimestamp(ApiData apiData) { // we will not update api timestamps if we have no data or speeds are zero if (apiData == null) { // TODO debug log no api data return; } if (apiData.AlgorithmSpeedsTotal == null && apiData.AlgorithmSpeedsPerDevice == null) { // TODO debug log cannot get speeds return; } var speedsTotalSum = apiData.AlgorithmSpeedsTotal?.Select(p => p.Speed).Sum() ?? 0d; var perDevSpeedsTotalSum = apiData.AlgorithmSpeedsPerDevice?.Values.SelectMany(pl => pl).Select(p => p.Speed).Sum() ?? 0d; if (speedsTotalSum == 0d && perDevSpeedsTotalSum == 0d) { // TODO debug log speeds are zero return; } if (speedsTotalSum == _lastSpeedsTotalSum && perDevSpeedsTotalSum == _lastPerDevSpeedsTotalSum) { // TODO debug log speeds seem to be stuck return; } // update _lastSpeedsTotalSum = speedsTotalSum; _lastPerDevSpeedsTotalSum = perDevSpeedsTotalSum; MinerApiWatchdog.UpdateApiTimestamp(GroupKey, DateTime.UtcNow); }
public void Stop() { // TODO thing about this case, closing opening on switching // EthlargementIntegratedPlugin.Instance.Stop(_miningPairs); MinerApiWatchdog.RemoveGroup(GroupKey); MiningStats.RemoveGroup(MiningPairs.Select(pair => pair.Device.UUID), _plugin.PluginUUID); IsRunning = false; _miner.StopMining(); //if (_miner is IDisposable disposableMiner) //{ // disposableMiner.Dispose(); //} }
// TODO this thing public void Start(string miningLocation, string username) { if (_isEnded) { return; } _miner.InitMiningLocationAndUsername(miningLocation, username); _miner.InitMiningPairs(MiningPairs); EthlargementIntegratedPlugin.Instance.Start(MiningPairs); _miner.StartMining(); IsRunning = true; // maxTimeout = ConfigManager.GeneralConfig.CoolDownCheckEnabled var maxTimeout = _plugin.GetApiMaxTimeout(MiningPairs); MinerApiWatchdog.AddGroup(GroupKey, maxTimeout, DateTime.UtcNow); }