Added the ability to set a maximum CPM inside a Config Settings.

This commit is contained in:
ruri
2019-05-09 02:08:04 +02:00
parent 74d5aa3436
commit 631f9b3cb9
4 changed files with 50 additions and 18 deletions
+4
View File
@@ -21,6 +21,10 @@ namespace RuriLib
/// <summary>The suggested amount of Bots that should be used with the config.</summary>
public int SuggestedBots { get { return suggestedBots; } set { suggestedBots = value; OnPropertyChanged(); } }
private int maxCPM = 0;
/// <summary>The maximum CPM around which the Master Worker will stop starting bots and wait for the CPM to decrease below the threshold.</summary>
public int MaxCPM { get { return maxCPM; } set { maxCPM = value; OnPropertyChanged(); } }
private DateTime lastModified = DateTime.Now;
/// <summary>When the Config was last modified.</summary>
public DateTime LastModified { get { return lastModified; } set { lastModified = value; OnPropertyChanged(); } }
+34 -9
View File
@@ -97,8 +97,16 @@ namespace RuriLib.Runner
{
get
{
if (TestedCount == 0) cpm = 0;
if (IsCPMLocked) return cpm;
if (TestedCount == 0)
{
cpm = 0;
return cpm;
}
if (IsCPMLocked)
{
return cpm;
}
try
{
@@ -113,6 +121,7 @@ namespace RuriLib.Runner
}
catch { }
finally { IsCPMLocked = false; }
return cpm;
}
}
@@ -415,6 +424,13 @@ namespace RuriLib.Runner
// Checking Process
foreach (var data in DataPool.List.Skip(StartingPoint - 1))
{
// Check if there is a cancellation request
if (Master.CancellationPending)
{
AbortAllBots();
return;
}
// Create an instance of CData basing on the current data line
CData c = new CData(data, Env.GetWordlistType(Wordlist.Type));
@@ -501,15 +517,24 @@ namespace RuriLib.Runner
RaiseSaveProgress();
}
// Search for the first available bot, assign the data to it and start its job
foreach (var bot in Bots)
// If we are above the CPM limit, go to the wait (use cpm NOT CPM so it doesn't calculate it uselessly when it checks the IF conditions)
if (Config.Settings.MaxCPM > 0 && cpm >= Config.Settings.MaxCPM)
{
if (!bot.Worker.IsBusy)
// Update the CPM and go directly to the wait (which will update the other stats too)
UpdateCPM();
}
else
{
// Search for the first available bot, assign the data to it and start its job
foreach (var bot in Bots)
{
RaiseMessageArrived(LogLevel.Info, "Assigned data " + data + " to bot " + bot.Id, false);
bot.Worker.RunWorkerAsync(data);
assigned = true;
break;
if (!bot.Worker.IsBusy)
{
RaiseMessageArrived(LogLevel.Info, "Assigned data " + data + " to bot " + bot.Id, false);
bot.Worker.RunWorkerAsync(data);
assigned = true;
break;
}
}
}