rendered paste body#!/usr/bin/env perl
#use Time::HiRes qw/ usleep /;
use YAML;
use FindBin qw/$Bin/;
use Data::Dumper;
use lib "$Bin/../lib";
use strategy::Scheduler;
my $config = YAML::LoadFile("$Bin/../strategy.yml");
my $sc = new strategy::Scheduler($config);
my $pids = 0;
my $maxpids = $sc->conf->{scheduler}->{num_processes} || ConfigError("scheduler->num_processes not defined");
sub wait_finished_child {
$pids--;
wait();
}
$SIG{CHLD} = \&wait_finished_child;
# main program loop
while(1) {
print "Looking for databases to backup.. [" . scalar localtime() . "]\n";
my $runs = $sc->db->resultset('Schedule')->get_runs;
while(my $run = $runs->next) {
start_new_child();
}
sleep(100);
print "Waiting 600 seconds.. [" . scalar localtime() . "]\n";
}
sub start_new_child {
if($pids < $maxpids) {
my $newpid = fork();
if($newpid > 0) {
$pids++;
} elsif(defined $newpid) {
print "pid: $$ ($pids of $maxpids) spawned\n";
sleep 2;
exit(0);
} else { die $!; }
} else {
sleep 60;
}
}
sub ConfigError {
my $msg = shift;
die("Configuration Error: $msg\nConfigfile: ($Bin/../strategy.yml) ");
}