diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm index 830950a0..602f8a94 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm @@ -9,7 +9,7 @@ use Role::Tiny; use namespace::clean; use App::Netdisco::JobQueue qw/jq_locked jq_getsome jq_lock/; -use MCE::Util 'get_ncpu'; +use MCE::Util (); sub worker_begin { my $self = shift; @@ -27,7 +27,7 @@ sub worker_begin { if (scalar @jobs) { info sprintf "mgr (%s): found %s jobs booked to this processing node", $wid, scalar @jobs; - $self->{queue}->enqueue(@jobs); # FIXME priority and freeze + $self->{queue}->enqueue(@jobs); } } @@ -38,8 +38,9 @@ sub worker_body { return debug "mgr ($wid): no need for manager... quitting" if setting('workers')->{'no_manager'}; - # FIXME really the best strategy? - my $num_slots = (MCE::Util::get_ncpu() * 2) - $self->{queue}->pending(); + my $num_slots = + MCE::Util::_parse_max_workers( setting('workers')->{pollers} ) + - $self->{queue}->pending(); while (1) { debug "mgr ($wid): getting potential jobs for $num_slots workers"; @@ -55,7 +56,7 @@ sub worker_body { $wid, $job->id; # copy job to local queue - $self->{queue}->enqueue($job); # FIXME priority and freeze + $self->{queue}->enqueue($job); } debug "mgr ($wid): sleeping now..."; diff --git a/Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm b/Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm index ae321e54..861a4a5b 100644 --- a/Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm +++ b/Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm @@ -29,10 +29,18 @@ sub jq_getsome { my $rs = schema('netdisco')->resultset('Admin') ->search( - {status => 'queued'}, + {status => 'queued', action => { -in => setting('job_prio')->{high} } }, {order_by => 'random()', rows => ($num_slots || 1)}, ); + unless ($rs->count) { + $rs = schema('netdisco')->resultset('Admin') + ->search( + {status => 'queued', action => { -in => setting('job_prio')->{normal} } }, + {order_by => 'random()', rows => ($num_slots || 1)}, + ); + } + while (my $job = $rs->next) { push @returned, schema('daemon')->resultset('Admin') ->new_result({ $job->get_columns }); diff --git a/Netdisco/lib/App/Netdisco/Web/AdminTask.pm b/Netdisco/lib/App/Netdisco/Web/AdminTask.pm index 7134d86d..e0986398 100644 --- a/Netdisco/lib/App/Netdisco/Web/AdminTask.pm +++ b/Netdisco/lib/App/Netdisco/Web/AdminTask.pm @@ -25,7 +25,9 @@ sub add_job { }); } -foreach my $action (keys %{ setting('job_types') }) { +foreach my $action (@{ setting('job_prio')->{high} }, + @{ setting('job_prio')->{normal} }) { + ajax "/ajax/control/admin/$action" => require_role admin => sub { add_job($action, param('device'), param('extra')); }; diff --git a/Netdisco/share/config.yml b/Netdisco/share/config.yml index 4c70e44f..2f5ee55c 100644 --- a/Netdisco/share/config.yml +++ b/Netdisco/share/config.yml @@ -193,26 +193,24 @@ dns: # expire: # when: '20 23 * * *' -job_types: - discoverall: Poller - discover: Poller - arpwalk: Poller - arpnip: Poller - macwalk: Poller - macsuck: Poller - nbtwalk: Poller - nbtstat: Poller - expire: Poller - location: Interactive - contact: Interactive - portcontrol: Interactive - portname: Interactive - vlan: Interactive - power: Interactive - -job_type_keys: - Poller: pollers - Interactive: interactives +job_prio: + high: + - location + - contact + - portcontrol + - portname + - vlan + - power + normal: + - discoverall + - discover + - arpwalk + - arpnip + - macwalk + - macsuck + - nbtwalk + - nbtstat + - expire # --------------- # GraphViz Export