Time handling for rewarder
This commit is contained in:
parent
48e7f98956
commit
2ab84e2a61
|
@ -20,11 +20,11 @@ namespace TestNetRewarder
|
||||||
|
|
||||||
public async Task ProcessTimeSegment(TimeRange timeRange)
|
public async Task ProcessTimeSegment(TimeRange timeRange)
|
||||||
{
|
{
|
||||||
|
var connector = GethConnector.GethConnector.Initialize(log);
|
||||||
|
if (connector == null) throw new Exception("Invalid Geth information");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var connector = GethConnector.GethConnector.Initialize(log);
|
|
||||||
if (connector == null) return;
|
|
||||||
|
|
||||||
var blockRange = connector.GethNode.ConvertTimeRangeToBlockRange(timeRange);
|
var blockRange = connector.GethNode.ConvertTimeRangeToBlockRange(timeRange);
|
||||||
if (!IsNewBlockRange(blockRange))
|
if (!IsNewBlockRange(blockRange))
|
||||||
{
|
{
|
||||||
|
@ -33,12 +33,12 @@ namespace TestNetRewarder
|
||||||
}
|
}
|
||||||
|
|
||||||
var chainState = new ChainState(historicState, connector.CodexContracts, blockRange);
|
var chainState = new ChainState(historicState, connector.CodexContracts, blockRange);
|
||||||
await ProcessTimeSegment(chainState);
|
await ProcessChainState(chainState);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Error("Exception processing time segment: " + ex);
|
log.Error("Exception processing time segment: " + ex);
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ namespace TestNetRewarder
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ProcessTimeSegment(ChainState chainState)
|
private async Task ProcessChainState(ChainState chainState)
|
||||||
{
|
{
|
||||||
var outgoingRewards = new List<RewardUsersCommand>();
|
var outgoingRewards = new List<RewardUsersCommand>();
|
||||||
foreach (var reward in rewardRepo.Rewards)
|
foreach (var reward in rewardRepo.Rewards)
|
||||||
|
@ -63,6 +63,7 @@ namespace TestNetRewarder
|
||||||
ProcessReward(outgoingRewards, reward, chainState);
|
ProcessReward(outgoingRewards, reward, chainState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Log($"Found {outgoingRewards.Count} rewards to send.");
|
||||||
if (outgoingRewards.Any())
|
if (outgoingRewards.Any())
|
||||||
{
|
{
|
||||||
if (!await SendRewardsCommand(outgoingRewards))
|
if (!await SendRewardsCommand(outgoingRewards))
|
||||||
|
@ -79,7 +80,7 @@ namespace TestNetRewarder
|
||||||
Rewards = outgoingRewards.ToArray()
|
Rewards = outgoingRewards.ToArray()
|
||||||
};
|
};
|
||||||
|
|
||||||
log.Log("Sending rewards: " + JsonConvert.SerializeObject(cmd));
|
log.Debug("Sending rewards: " + JsonConvert.SerializeObject(cmd));
|
||||||
return await Program.BotClient.SendRewards(cmd);
|
return await Program.BotClient.SendRewards(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,12 @@ namespace TestNetRewarder
|
||||||
if (end > now)
|
if (end > now)
|
||||||
{
|
{
|
||||||
// Wait for the entire time segment to be in the past.
|
// Wait for the entire time segment to be in the past.
|
||||||
var delay = (end - now).Add(TimeSpan.FromSeconds(3));
|
var delay = end - now;
|
||||||
waited = true;
|
waited = true;
|
||||||
log.Log($"Waiting till time segment is in the past... {Time.FormatDuration(delay)}");
|
log.Log($"Waiting till time segment is in the past... {Time.FormatDuration(delay)}");
|
||||||
await Task.Delay(delay, Program.CancellationToken);
|
await Task.Delay(delay, Program.CancellationToken);
|
||||||
}
|
}
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(3), Program.CancellationToken);
|
||||||
|
|
||||||
if (Program.CancellationToken.IsCancellationRequested) return;
|
if (Program.CancellationToken.IsCancellationRequested) return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue