support IP prefix enum expansion in scheduler

This commit is contained in:
Oliver Gorwits
2018-02-23 23:38:11 +00:00
parent 83752aff2c
commit 5a5970e220
2 changed files with 23 additions and 11 deletions

View File

@@ -3,6 +3,7 @@
[ENHANCEMENTS]
* use PG COPY for bulk insert of jobs with prefix
* support IP prefix enum expansion in scheduler
2.039010 - 2018-02-22

View File

@@ -2,9 +2,9 @@ package App::Netdisco::Backend::Role::Scheduler;
use Dancer qw/:moose :syntax :script/;
use NetAddr::IP;
use Algorithm::Cron;
use App::Netdisco::Util::MCE;
use App::Netdisco::JobQueue qw/jq_insert/;
use Role::Tiny;
@@ -60,8 +60,7 @@ sub worker_body {
# if any job is due, add it to the queue
foreach my $action (keys %{ setting('schedule') }) {
my $sched = setting('schedule')->{$action}
or next;
my $sched = setting('schedule')->{$action} or next;
my $real_action = ($sched->{action} || $action);
# next occurence of job must be in this minute's window
@@ -69,14 +68,26 @@ sub worker_body {
$win_start, $win_end, $sched->{when}->next_time($win_start);
next unless $sched->{when}->next_time($win_start) <= $win_end;
# queue it!
info "sched ($wid): queueing $real_action job";
jq_insert({
action => $real_action,
device => $sched->{device},
port => $sched->{port},
extra => $sched->{extra},
});
my $net = NetAddr::IP->new($sched->{device});
next if ($sched->{device}
and (!$net or $net->num == 0 or $net->addr eq '0.0.0.0'));
my @hostlist = map { (ref $_) ? $_->addr : undef }
(defined $sched->{device} ? ($net->hostenum) : (undef));
my @job_specs = ();
foreach my $host (@hostlist) {
push @job_specs, {
action => $real_action,
device => $host,
port => $sched->{port},
subaction => $sched->{extra},
};
}
info sprintf 'sched (%s): queueing %s %s jobs',
$wid, (scalar @job_specs), $real_action;
jq_insert( \@job_specs );
}
}
}