From 319489ae00604e1b1ca9f0dc908ff74bad3a9baf Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 24 Apr 2014 21:46:30 +0100 Subject: [PATCH] remove job types from scheduler --- .../App/Netdisco/Daemon/Worker/Scheduler.pm | 38 +++++-------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Scheduler.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Scheduler.pm index f6f24f2d..7dbfc2e8 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Scheduler.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Scheduler.pm @@ -9,30 +9,16 @@ use Try::Tiny; use Role::Tiny; use namespace::clean; -my $jobactions = { - map {$_ => undef} qw/ - discoverall - arpwalk - macwalk - nbtwalk - expire - / -# saveconfigs -# backup -}; - sub worker_begin { my $self = shift; my $wid = $self->wid; debug "entering Scheduler ($wid) worker_begin()"; - foreach my $a (keys %$jobactions) { - next unless setting('housekeeping') - and exists setting('housekeeping')->{$a}; - my $config = setting('housekeeping')->{$a}; + foreach my $action (keys %{ setting('housekeeping') }) { + my $config = setting('housekeeping')->{$action}; # accept either single crontab format, or individual time fields - my $cron = Algorithm::Cron->new( + $config->{when} = Algorithm::Cron->new( base => 'local', %{ (ref {} eq ref $config->{when}) @@ -40,9 +26,6 @@ sub worker_begin { : {crontab => $config->{when}} } ); - - $jobactions->{$a} = $config; - $jobactions->{$a}->{when} = $cron; } } @@ -61,29 +44,26 @@ sub worker_body { my $win_end = $win_start + 60; # if any job is due, add it to the queue - foreach my $a (keys %$jobactions) { - next unless defined $jobactions->{$a}; - my $sched = $jobactions->{$a}; + foreach my $action (keys %{ setting('housekeeping') }) { + my $sched = setting('housekeeping')->{$action}; # 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); next unless $sched->{when}->next_time($win_start) <= $win_end; # queue it! - # due to a table constraint, this will (intentionally) fail if a - # similar job is already queued. try { - info "sched ($wid): queueing $a job"; + info "sched ($wid): queueing $action job"; schema('netdisco')->resultset('Admin')->create({ - action => $a, + action => $action, device => ($sched->{device} || undef), subaction => ($sched->{extra} || undef), status => 'queued', }); } catch { - debug "sched ($wid): action $a was not queued (dupe?)"; + debug "sched ($wid): action $action was not queued (dupe?)"; }; } }