remove job types from scheduler

This commit is contained in:
Oliver Gorwits
2014-04-24 21:46:30 +01:00
parent ccdeca600c
commit 319489ae00

View File

@@ -9,30 +9,16 @@ use Try::Tiny;
use Role::Tiny; use Role::Tiny;
use namespace::clean; use namespace::clean;
my $jobactions = {
map {$_ => undef} qw/
discoverall
arpwalk
macwalk
nbtwalk
expire
/
# saveconfigs
# backup
};
sub worker_begin { sub worker_begin {
my $self = shift; my $self = shift;
my $wid = $self->wid; my $wid = $self->wid;
debug "entering Scheduler ($wid) worker_begin()"; debug "entering Scheduler ($wid) worker_begin()";
foreach my $a (keys %$jobactions) { foreach my $action (keys %{ setting('housekeeping') }) {
next unless setting('housekeeping') my $config = setting('housekeeping')->{$action};
and exists 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( $config->{when} = Algorithm::Cron->new(
base => 'local', base => 'local',
%{ %{
(ref {} eq ref $config->{when}) (ref {} eq ref $config->{when})
@@ -40,9 +26,6 @@ sub worker_begin {
: {crontab => $config->{when}} : {crontab => $config->{when}}
} }
); );
$jobactions->{$a} = $config;
$jobactions->{$a}->{when} = $cron;
} }
} }
@@ -61,29 +44,26 @@ sub worker_body {
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
foreach my $a (keys %$jobactions) { foreach my $action (keys %{ setting('housekeeping') }) {
next unless defined $jobactions->{$a}; my $sched = setting('housekeeping')->{$action};
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
debug sprintf "sched ($wid): $a: win_start: %s, win_end: %s, next: %s", debug sprintf "sched ($wid): $action: win_start: %s, win_end: %s, next: %s",
$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! # queue it!
# due to a table constraint, this will (intentionally) fail if a
# similar job is already queued.
try { try {
info "sched ($wid): queueing $a job"; info "sched ($wid): queueing $action job";
schema('netdisco')->resultset('Admin')->create({ schema('netdisco')->resultset('Admin')->create({
action => $a, action => $action,
device => ($sched->{device} || undef), device => ($sched->{device} || undef),
subaction => ($sched->{extra} || undef), subaction => ($sched->{extra} || undef),
status => 'queued', status => 'queued',
}); });
} }
catch { catch {
debug "sched ($wid): action $a was not queued (dupe?)"; debug "sched ($wid): action $action was not queued (dupe?)";
}; };
} }
} }