Skip to content

Commit

Permalink
Use Train Helper Method Instead of Schedule.TrainingNow
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCatarino committed Oct 28, 2019
1 parent 5bb28b4 commit 4970165
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 13 additions & 1 deletion Algorithm.CSharp/TrainingInitializeRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,19 @@ public override void Initialize()
// this should cause the algorithm to fail
// the regression test sets the time limit to 30 seconds and there's one extra
// minute in the bucket, so a two minute sleep should result in RuntimeError
Schedule.TrainingNow(() => Thread.Sleep(TimeSpan.FromMinutes(2.5)));
Train(() => Thread.Sleep(TimeSpan.FromMinutes(2.5)));

// DateRules.Tomorrow combined with TimeRules.Midnight enforces that this event schedule will
// have exactly one time, which will fire between the first data point and the next day at
// midnight. So after the first data point, it will run this event and sleep long enough to
// exceed the static max algorithm time loop time and begin to consume from the leaky bucket
// the regression test sets the "algorithm-manager-time-loop-maximum" value to 30 seconds
Train(DateRules.Tomorrow, TimeRules.Midnight, () =>
{
// this will consume the single 'minute' available in the leaky bucket
// and the regression test will confirm that the leaky bucket is empty
Thread.Sleep(TimeSpan.FromMinutes(1));
});
}

public bool CanRunLocally => false;
Expand Down
11 changes: 10 additions & 1 deletion Algorithm.Python/TrainingInitializeRegressionAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,13 @@ def Initialize(self):
# this should cause the algorithm to fail
# the regression test sets the time limit to 30 seconds and there's one extra
# minute in the bucket, so a two minute sleep should result in RuntimeError
self.Schedule.TrainingNow(lambda: sleep(150))
self.Train(lambda: sleep(150))

# DateRules.Tomorrow combined with TimeRules.Midnight enforces that this event schedule will
# have exactly one time, which will fire between the first data point and the next day at
# midnight. So after the first data point, it will run this event and sleep long enough to
# exceed the static max algorithm time loop time and begin to consume from the leaky bucket
# the regression test sets the "algorithm-manager-time-loop-maximum" value to 30 seconds
self.Train(self.DateRules.Tomorrow, self.TimeRules.Midnight, lambda: sleep(60))
# this will consume the single 'minute' available in the leaky bucket
# and the regression test will confirm that the leaky bucket is empty

0 comments on commit 4970165

Please sign in to comment.