Add -i option as exit condition

After -i# iterations sampler and sink will exit RUNNING state.
This commit is contained in:
Dennis Klein
2019-01-30 18:32:39 +01:00
committed by Dennis Klein
parent 14980d7486
commit b53691c8ad
6 changed files with 47 additions and 2 deletions

View File

@@ -26,6 +26,12 @@ Sampler::Sampler()
{
}
void Sampler::InitTask()
{
fIterations = fConfig->GetValue<uint64_t>("iterations");
fCounter = 0;
}
bool Sampler::ConditionalRun()
{
std::this_thread::sleep_for(std::chrono::seconds(1));
@@ -43,6 +49,14 @@ bool Sampler::ConditionalRun()
return false;
}
if (fIterations > 0) {
++fCounter;
if (fCounter >= fIterations) {
LOG(info) << "Sent " << fCounter << " messages. Finished.";
return false;
}
}
return true;
}