Skip to content

Commit 5c71c24

Browse files
committed
Delete delete running configuration only before bootstrap exit or miners restart.
1 parent ad6b3fc commit 5c71c24

15 files changed

+249
-205
lines changed

xmr-stak-bootstrap/Core/Finalizer.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Threading;
43

54
namespace XmrStakBootstrap.Core
65
{
76
public class Finalizer : IFinalizer
87
{
98
private readonly IList<Action> _actions = new List<Action>();
9+
private readonly object _lock = new object();
1010

1111
public void DoFinalize()
1212
{
13-
if (_actions.Count == 0) return;
14-
15-
Console.WriteLine(@"Waiting 10 seconds before finalization.");
16-
Thread.Sleep(10000);
17-
18-
foreach (var action in _actions)
13+
lock (_lock)
1914
{
20-
action();
15+
if (_actions.Count == 0) return;
16+
17+
foreach (var action in _actions)
18+
{
19+
action();
20+
}
2121
}
2222
}
2323

2424
public void ScheduleFinalization(Action action)
2525
{
26-
if (action == null) return;
26+
lock (_lock)
27+
{
28+
if (action == null) return;
2729

28-
_actions.Add(action);
30+
_actions.Add(action);
31+
}
2932
}
3033
}
3134
}

xmr-stak-bootstrap/Core/Runner/Generator/ConfigurationGeneratorRunner.cs renamed to xmr-stak-bootstrap/Core/Job/Generator/ConfigurationGeneratorJob.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
using Unity.Attributes;
22
using XmrStakBootstrap.RunConfiguration.Model;
33

4-
namespace XmrStakBootstrap.Core.Runner.Generator
4+
namespace XmrStakBootstrap.Core.Job.Generator
55
{
6-
public class ConfigurationGeneratorRunner : IRunner
6+
public class ConfigurationGeneratorJob : IJob
77
{
88
[Dependency]
99
public ISampleConfigurationGenerator SampleConfigurationGenerator { get; set; }
1010

1111
[Dependency]
1212
public RunConfigurationModel RunConfiguration { get; set; }
1313

14-
public void Run()
14+
public void Execute()
1515
{
1616
SampleConfigurationGenerator.Generate(RunConfiguration.GenerateConfiguration);
1717
}

xmr-stak-bootstrap/Core/Runner/Generator/ISampleConfigurationGenerator.cs renamed to xmr-stak-bootstrap/Core/Job/Generator/ISampleConfigurationGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace XmrStakBootstrap.Core.Runner.Generator
1+
namespace XmrStakBootstrap.Core.Job.Generator
22
{
33
public interface ISampleConfigurationGenerator
44
{

xmr-stak-bootstrap/Core/Runner/Generator/SampleConfigurationGenerator.cs renamed to xmr-stak-bootstrap/Core/Job/Generator/SampleConfigurationGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using XmrStakBootstrap.MasterConfiguration.Model;
55
using XmrStakBootstrap.Properties;
66

7-
namespace XmrStakBootstrap.Core.Runner.Generator
7+
namespace XmrStakBootstrap.Core.Job.Generator
88
{
99
public class SampleConfigurationGenerator : ISampleConfigurationGenerator
1010
{

xmr-stak-bootstrap/Core/Job/IJob.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace XmrStakBootstrap.Core.Job
2+
{
3+
public interface IJob
4+
{
5+
void Execute();
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace XmrStakBootstrap.Core.Job.Miner
2+
{
3+
public interface IMinerRunner
4+
{
5+
void Run();
6+
}
7+
}

xmr-stak-bootstrap/Core/Runner/Miner/MinerRunner.cs renamed to xmr-stak-bootstrap/Core/Job/Miner/MinerRunner.cs

Lines changed: 10 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -6,94 +6,24 @@
66
using Newtonsoft.Json;
77
using Unity.Attributes;
88
using XmrStakBootstrap.Common;
9-
using XmrStakBootstrap.Common.Menu;
109
using XmrStakBootstrap.MasterConfiguration.Model;
1110
using XmrStakBootstrap.RunConfiguration.Model;
1211

13-
namespace XmrStakBootstrap.Core.Runner.Miner
12+
namespace XmrStakBootstrap.Core.Job.Miner
1413
{
15-
public class MinerRunner : IRunner
14+
public class MinerRunner : IMinerRunner
1615
{
1716
[Dependency]
1817
public IFinalizer Finalizer { get; set; }
1918

20-
[Dependency]
21-
public RunConfigurationModel RunConfigurationModel { get; set; }
22-
2319
[Dependency]
2420
public MasterConfigurationModel MasterConfigurationModel { get; set; }
2521

26-
private bool HasSolution
27-
=>
28-
MasterConfigurationModel.SolutionProfiles.ContainsKey(
29-
RunConfigurationModel.ActiveSolutionConfiguration ?? string.Empty);
30-
31-
private bool HasWorkload
32-
=>
33-
MasterConfigurationModel.WorkloadProfiles.ContainsKey(
34-
RunConfigurationModel.ActiveWorkloadConfiguration ?? string.Empty);
35-
36-
private bool CanRun => HasSolution && HasWorkload;
22+
[Dependency]
23+
public RunConfigurationModel RunConfigurationModel { get; set; }
3724

3825
public void Run()
3926
{
40-
if (MasterConfigurationModel == null)
41-
{
42-
Console.WriteLine(@"Master configuration file '{0}' was not loaded. Try running this program with argument --help.", RunConfigurationModel.MasterConfiguration);
43-
return;
44-
}
45-
46-
var @continue = true;
47-
while (@continue)
48-
{
49-
Console.Clear();
50-
Console.WriteLine(@"Active solution: {0}", HasSolution ? RunConfigurationModel.ActiveSolutionConfiguration : "<UNKNOWN>");
51-
Console.WriteLine(@"Active workload: {0}", HasWorkload ? RunConfigurationModel.ActiveWorkloadConfiguration : "<UNKNOWN>");
52-
Console.WriteLine();
53-
Console.WriteLine(@"What would you like to do?");
54-
55-
@continue = MenuBuilder
56-
.Create(() => true)
57-
.AddConditionalOption(@"Start/restart miners", CanRun, () =>
58-
{
59-
DoRun();
60-
return false;
61-
})
62-
.AddEnabledOption(@"Change solution", () =>
63-
{
64-
SelectSolution();
65-
return true;
66-
})
67-
.AddEnabledOption(@"Change workload", () =>
68-
{
69-
SelectWorkload();
70-
return true;
71-
})
72-
.AddEnabledOption(@"Exit", () =>
73-
{
74-
Environment.Exit(0);
75-
return false;
76-
})
77-
.AddEnabledOption(@"Exit & terminate miners", () =>
78-
{
79-
KillMiners();
80-
Environment.Exit(0);
81-
return false;
82-
})
83-
.Execute();
84-
}
85-
}
86-
87-
private class UtilizedHardware
88-
{
89-
public HardwareEntry Hardware { get; set; }
90-
public string Profile { get; set; }
91-
}
92-
93-
private void DoRun()
94-
{
95-
KillMiners();
96-
9727
var solution = MasterConfigurationModel.SolutionProfiles.GetValue(RunConfigurationModel.ActiveSolutionConfiguration);
9828
var workload = MasterConfigurationModel.WorkloadProfiles.GetValue(RunConfigurationModel.ActiveWorkloadConfiguration);
9929

@@ -124,22 +54,6 @@ private void DoRun()
12454
}
12555
}
12656

127-
private void SelectSolution()
128-
{
129-
Console.WriteLine(@"Available solutions: ");
130-
RunConfigurationModel.ActiveSolutionConfiguration =
131-
MenuBuilder.CreateTextListMenu(MasterConfigurationModel.SolutionProfiles.Keys)
132-
.Execute();
133-
}
134-
135-
private void SelectWorkload()
136-
{
137-
Console.WriteLine(@"Available workloads: ");
138-
RunConfigurationModel.ActiveWorkloadConfiguration =
139-
MenuBuilder.CreateTextListMenu(MasterConfigurationModel.WorkloadProfiles.Keys)
140-
.Execute();
141-
}
142-
14357
private List<PrioritizedPoolEntry> GetOutputPools(IEnumerable<string> pools)
14458
{
14559
return pools
@@ -178,7 +92,7 @@ private string GetConfigurationArgument(IReadOnlyCollection<PrioritizedPoolEntry
17892
return $"--config \"{configPath}\"";
17993
}
18094

181-
private string GetCpuArgument(IList<UtilizedHardware> entry)
95+
private string GetCpuArgument(ICollection<UtilizedHardware> entry)
18296
{
18397
if (entry.Count == 0)
18498
{
@@ -192,7 +106,7 @@ private string GetCpuArgument(IList<UtilizedHardware> entry)
192106
return $"--cpu \"{path}\"";
193107
}
194108

195-
private string GetAmdArgument(IList<UtilizedHardware> entry)
109+
private string GetAmdArgument(ICollection<UtilizedHardware> entry)
196110
{
197111
if (entry.Count == 0)
198112
{
@@ -219,7 +133,7 @@ private string GetAmdArgument(IList<UtilizedHardware> entry)
219133
return $"--amd \"{path}\"";
220134
}
221135

222-
private string GetNvidiaArgument(IList<UtilizedHardware> entry)
136+
private string GetNvidiaArgument(ICollection<UtilizedHardware> entry)
223137
{
224138
if (entry.Count == 0)
225139
{
@@ -274,31 +188,10 @@ private void ScheduleFileDelete(string file)
274188
});
275189
}
276190

277-
private static void KillMiners()
278-
{
279-
foreach (var process in Process.GetProcessesByName("xmr-stak"))
280-
{
281-
KillProcess(process);
282-
}
283-
}
284-
285-
private static void KillProcess(Process process)
286-
{
287-
KillProcess(process.Id, process);
288-
}
289-
290-
private static void KillProcess(int processId, Process process)
191+
private class UtilizedHardware
291192
{
292-
try
293-
{
294-
process.Kill();
295-
process.Dispose();
296-
Console.WriteLine(@"Process {0} was killed.", processId);
297-
}
298-
catch (Exception)
299-
{
300-
Console.WriteLine(@"Cannot kill process {0}!", processId);
301-
}
193+
public HardwareEntry Hardware { get; set; }
194+
public string Profile { get; set; }
302195
}
303196
}
304197
}

0 commit comments

Comments
 (0)