fixes and log messages
This commit is contained in:
@@ -33,7 +33,7 @@ mkdir $tmp_dir if ! -d $tmp_dir;
|
|||||||
|
|
||||||
my $mce = MCE->new(
|
my $mce = MCE->new(
|
||||||
spawn_delay => 0.15,
|
spawn_delay => 0.15,
|
||||||
job_delay => 0.15,
|
job_delay => 1.15,
|
||||||
tmp_dir => $tmp_dir,
|
tmp_dir => $tmp_dir,
|
||||||
user_func => sub { $_[0]->worker_body },
|
user_func => sub { $_[0]->worker_body },
|
||||||
on_post_exit => \&restart_worker,
|
on_post_exit => \&restart_worker,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use namespace::clean;
|
|||||||
my $jobactions = {
|
my $jobactions = {
|
||||||
map {$_ => undef} qw/
|
map {$_ => undef} qw/
|
||||||
/
|
/
|
||||||
|
# saveconfigs
|
||||||
# discoverall
|
# discoverall
|
||||||
# refresh
|
# refresh
|
||||||
# macwalk
|
# macwalk
|
||||||
@@ -31,11 +32,14 @@ sub worker_begin {
|
|||||||
my $config = setting('housekeeping')->{$a};
|
my $config = setting('housekeeping')->{$a};
|
||||||
|
|
||||||
# accept either single crontab format, or individual time fields
|
# accept either single crontab format, or individual time fields
|
||||||
my $cron = Algorithm::Cron->new(%{
|
my $cron = Algorithm::Cron->new(
|
||||||
ref {} eq ref $config->{when}
|
base => 'local',
|
||||||
? $config->{when}
|
%{
|
||||||
: {crontab => $config->{when}}
|
(ref {} eq ref $config->{when})
|
||||||
});
|
? $config->{when}
|
||||||
|
: {crontab => $config->{when}}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$jobactions->{$a} = $config;
|
$jobactions->{$a} = $config;
|
||||||
$jobactions->{$a}->{when} = $cron;
|
$jobactions->{$a}->{when} = $cron;
|
||||||
@@ -49,10 +53,11 @@ sub worker_body {
|
|||||||
while (1) {
|
while (1) {
|
||||||
# sleep until some point in the next minute
|
# sleep until some point in the next minute
|
||||||
my $naptime = 60 - (time % 60) + int(rand(45));
|
my $naptime = 60 - (time % 60) + int(rand(45));
|
||||||
debug "scheduler ($wid): sleeping for $naptime seconds";
|
debug "sched ($wid): sleeping for $naptime seconds";
|
||||||
sleep $naptime;
|
sleep $naptime;
|
||||||
|
|
||||||
my $win_start = time - (time % 60);
|
# NB next_time() returns the next *after* win_start
|
||||||
|
my $win_start = time - (time % 60) - 1;
|
||||||
my $win_end = $win_start + 60;
|
my $win_end = $win_start + 60;
|
||||||
|
|
||||||
# if any job is due, add it to the queue
|
# if any job is due, add it to the queue
|
||||||
@@ -61,19 +66,24 @@ sub worker_body {
|
|||||||
my $sched = $jobactions->{$a};
|
my $sched = $jobactions->{$a};
|
||||||
|
|
||||||
# next occurence of job must be in this minute's window
|
# next occurence of job must be in this minute's window
|
||||||
next unless $sched->{when}->next_time($win_start) < $win_end;
|
debug sprintf "sched ($wid): $a: win_start: %s, win_end: %s, next: %s",
|
||||||
|
$win_start, $win_end, $sched->{when}->next_time($win_start);
|
||||||
|
next unless $sched->{when}->next_time($win_start) <= $win_end;
|
||||||
|
|
||||||
# queue it!
|
# queue it!
|
||||||
# due to a table constraint, this will (intentionally) fail if a
|
# due to a table constraint, this will (intentionally) fail if a
|
||||||
# similar job is already queued.
|
# similar job is already queued.
|
||||||
try {
|
try {
|
||||||
debug "scheduler ($wid): queueing $a job";
|
debug "sched ($wid): queueing $a job";
|
||||||
schema('netdisco')->resultset('Admin')->create({
|
schema('netdisco')->resultset('Admin')->create({
|
||||||
action => $a,
|
action => $a,
|
||||||
device => ($sched->{device} || undef),
|
device => ($sched->{device} || undef),
|
||||||
subaction => ($sched->{param} || undef),
|
subaction => ($sched->{param} || undef),
|
||||||
status => 'queued',
|
status => 'queued',
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
debug "sched ($wid): action $a was not queued (dupe?)";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user