Пример #1
0
        // TODO make Task
        public static async Task UpdateMiningSession(IEnumerable <ComputeDevice> devices, string username)
        {
            _switchingManager?.Stop();
            await _semaphore.WaitAsync();

            try
            {
                _username = username;
                // TODO check out if there is a change
                _miningDevices = GroupSetupUtils.GetMiningDevices(devices, true);
                if (_miningDevices.Count > 0)
                {
                    GroupSetupUtils.AvarageSpeeds(_miningDevices);
                    //// TODO enable StabilityAnalyzer
                    //// set benchmarked speeds for BenchmarkingAnalyzer
                    //foreach (var miningDev in _miningDevices)
                    //{
                    //    var deviceUuid = miningDev.Device.Uuid;
                    //    foreach (var algorithm in miningDev.Algorithms)
                    //    {
                    //        var speedID = $"{deviceUuid}-{algorithm.AlgorithmStringID}";
                    //        var benchmarkSpeed = new BenchmarkingAnalyzer.BenchmarkSpeed {
                    //            PrimarySpeed = algorithm.BenchmarkSpeed,
                    //            SecondarySpeed = algorithm.SecondaryAveragedSpeed,
                    //        };
                    //        BenchmarkingAnalyzer.SetBenchmarkSpeeds(speedID, benchmarkSpeed);
                    //    }
                    //}
                }
            }
            finally
            {
                _semaphore.Release();
            }
            _switchingManager?.ForceUpdate();
        }
        private static async Task MiningManagerCommandQueueLoop(CancellationToken stop)
        {
            var switchingManager = new AlgorithmSwitchingManager();

            try
            {
                switchingManager.SmaCheck += SwichMostProfitableGroupUpMethod;
                switchingManager.ForceUpdate();

                var         checkWaitTime = TimeSpan.FromMilliseconds(50);
                Func <bool> isActive      = () => !stop.IsCancellationRequested;
                Logger.Info(Tag, "Starting MiningManagerCommandQueueLoop");
                while (isActive())
                {
                    if (isActive())
                    {
                        await TaskHelpers.TryDelay(checkWaitTime, stop);
                    }
                    // command handling
                    if (isActive() && _commandQueue.TryDequeue(out var command))
                    {
                        await HandleCommand(command);
                    }
                }
            }
            catch (TaskCanceledException e)
            {
                Logger.Debug(Tag, $"MiningManagerCommandQueueLoop TaskCanceledException: {e.Message}");
            }
            finally
            {
                Logger.Info(Tag, "Exiting MiningManagerCommandQueueLoop run cleanup");
                // cleanup
                switchingManager.SmaCheck -= SwichMostProfitableGroupUpMethod;
                switchingManager.Stop();
                foreach (var groupMiner in _runningMiners.Values)
                {
                    await groupMiner.StopTask();
                }
                _runningMiners.Clear();
                _miningDevices.Clear();
                EthlargementIntegratedPlugin.Instance.Stop();
            }
        }
Пример #3
0
        private static async Task MiningManagerCommandQueueLoop(CancellationToken stop)
        {
            var switchingManager = new AlgorithmSwitchingManager();

            var         lastDeferredCommandTime = DateTime.UtcNow;
            Func <bool> handleDeferredCommands  = () => (DateTime.UtcNow - lastDeferredCommandTime).TotalSeconds >= 0.5;
            var         deferredCommands        = new List <DeferredDeviceCommand>();

            try
            {
                switchingManager.SmaCheck += SwichMostProfitableGroupUpMethod;
                switchingManager.ForceUpdate();

                var         checkWaitTime = TimeSpan.FromMilliseconds(50);
                Func <bool> isActive      = () => !stop.IsCancellationRequested;
                Logger.Info(Tag, "Starting MiningManagerCommandQueueLoop");
                while (isActive())
                {
                    if (isActive())
                    {
                        await TaskHelpers.TryDelay(checkWaitTime, stop);
                    }
                    if (handleDeferredCommands() && deferredCommands.Any())
                    {
                        await HandleDeferredCommands(deferredCommands);

                        deferredCommands.Clear();
                    }
                    // command handling
                    var(command, hasTimedout, exceptionString) = await _commandQueue.ReadAsync(checkWaitTime, stop);

                    if (command == null)
                    {
                        if (exceptionString != null)
                        {
                            Logger.Error(Tag, $"Channel.ReadAsync error: {exceptionString}");
                        }
                        continue;
                    }
                    if (command is DeferredDeviceCommand deferredCommand)
                    {
                        deferredCommand.device.IsPendingChange = true; // TODO check if we can be without this one
                        deferredCommand.device.State           = DeviceState.Pending;
                        lastDeferredCommandTime = DateTime.UtcNow;
                        deferredCommands.Add(deferredCommand);
                        continue;
                    }
                    if (command is MainCommand mainCommand)
                    {
                        await HandleCommand(mainCommand);
                    }
                }
            }
            catch (TaskCanceledException e)
            {
                Logger.Debug(Tag, $"MiningManagerCommandQueueLoop TaskCanceledException: {e.Message}");
            }
            finally
            {
                Logger.Info(Tag, "Exiting MiningManagerCommandQueueLoop run cleanup");
                // cleanup
                switchingManager.SmaCheck -= SwichMostProfitableGroupUpMethod;
                switchingManager.Stop();
                foreach (var groupMiner in _runningMiners.Values)
                {
                    await groupMiner.StopTask();
                }
                _runningMiners.Clear();
                _miningDevices.Clear();
            }
        }