remove job types from scheduler
This commit is contained in:
		| @@ -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?)"; | ||||
|           }; | ||||
|       } | ||||
|   } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user