Skip to content

Commit

Permalink
dird: remove inner loop from WaitForJobsToRun
Browse files Browse the repository at this point in the history
- waiting can be done every turn of the outside loop
  • Loading branch information
franku committed Nov 21, 2019
1 parent 925a31f commit d03435f
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions core/src/dird/scheduler_private.cc
Expand Up @@ -145,32 +145,27 @@ void SchedulerPrivate::WaitForJobsToRun()
next_job = prioritised_job_item_queue.TopItem();
if (!next_job.is_valid) { break; }

bool job_started = false;
while (active && !job_started) {
time_t now = time_adapter->time_source_->SystemTime();

if (now >= next_job.runtime) {
auto run_job =
prioritised_job_item_queue.TakeOutTopItemIfSame(next_job);
if (!run_job.is_valid) {
continue; // check queue again
}
JobControlRecord* jcr = TryCreateJobControlRecord(run_job);
Dmsg1(local_debuglevel, "Scheduler: Running job %s.",
run_job.job->resource_name_);
if (jcr != nullptr) { ExecuteJobCallback_(jcr); }
job_started = true;

} else {
time_t wait_interval{std::min(time_adapter->default_wait_interval_,
next_job.runtime - now)};
Dmsg2(local_debuglevel,
"Scheduler: WaitForJobsToRun is sleeping for %d seconds. Next "
"job: %s.",
wait_interval, next_job.job->resource_name_);

time_adapter->time_source_->SleepFor(seconds(wait_interval));
time_t now = time_adapter->time_source_->SystemTime();

if (now >= next_job.runtime) {
auto run_job = prioritised_job_item_queue.TakeOutTopItemIfSame(next_job);
if (!run_job.is_valid) {
continue; // check queue again
}
JobControlRecord* jcr = TryCreateJobControlRecord(run_job);
Dmsg1(local_debuglevel, "Scheduler: Running job %s.",
run_job.job->resource_name_);
if (jcr != nullptr) { ExecuteJobCallback_(jcr); }

} else {
time_t wait_interval{std::min(time_adapter->default_wait_interval_,
next_job.runtime - now)};
Dmsg2(local_debuglevel,
"Scheduler: WaitForJobsToRun is sleeping for %d seconds. Next "
"job: %s.",
wait_interval, next_job.job->resource_name_);

time_adapter->time_source_->SleepFor(seconds(wait_interval));
}
}
}
Expand Down

0 comments on commit d03435f

Please sign in to comment.