support IP prefix enum expansion in scheduler
This commit is contained in:
1
Changes
1
Changes
@@ -3,6 +3,7 @@
|
|||||||
[ENHANCEMENTS]
|
[ENHANCEMENTS]
|
||||||
|
|
||||||
* use PG COPY for bulk insert of jobs with prefix
|
* use PG COPY for bulk insert of jobs with prefix
|
||||||
|
* support IP prefix enum expansion in scheduler
|
||||||
|
|
||||||
2.039010 - 2018-02-22
|
2.039010 - 2018-02-22
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package App::Netdisco::Backend::Role::Scheduler;
|
|||||||
|
|
||||||
use Dancer qw/:moose :syntax :script/;
|
use Dancer qw/:moose :syntax :script/;
|
||||||
|
|
||||||
|
use NetAddr::IP;
|
||||||
use Algorithm::Cron;
|
use Algorithm::Cron;
|
||||||
use App::Netdisco::Util::MCE;
|
use App::Netdisco::Util::MCE;
|
||||||
|
|
||||||
use App::Netdisco::JobQueue qw/jq_insert/;
|
use App::Netdisco::JobQueue qw/jq_insert/;
|
||||||
|
|
||||||
use Role::Tiny;
|
use Role::Tiny;
|
||||||
@@ -60,8 +60,7 @@ sub worker_body {
|
|||||||
|
|
||||||
# if any job is due, add it to the queue
|
# if any job is due, add it to the queue
|
||||||
foreach my $action (keys %{ setting('schedule') }) {
|
foreach my $action (keys %{ setting('schedule') }) {
|
||||||
my $sched = setting('schedule')->{$action}
|
my $sched = setting('schedule')->{$action} or next;
|
||||||
or next;
|
|
||||||
my $real_action = ($sched->{action} || $action);
|
my $real_action = ($sched->{action} || $action);
|
||||||
|
|
||||||
# next occurence of job must be in this minute's window
|
# 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);
|
$win_start, $win_end, $sched->{when}->next_time($win_start);
|
||||||
next unless $sched->{when}->next_time($win_start) <= $win_end;
|
next unless $sched->{when}->next_time($win_start) <= $win_end;
|
||||||
|
|
||||||
# queue it!
|
my $net = NetAddr::IP->new($sched->{device});
|
||||||
info "sched ($wid): queueing $real_action job";
|
next if ($sched->{device}
|
||||||
jq_insert({
|
and (!$net or $net->num == 0 or $net->addr eq '0.0.0.0'));
|
||||||
action => $real_action,
|
|
||||||
device => $sched->{device},
|
my @hostlist = map { (ref $_) ? $_->addr : undef }
|
||||||
port => $sched->{port},
|
(defined $sched->{device} ? ($net->hostenum) : (undef));
|
||||||
extra => $sched->{extra},
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user