auto job priorities

This commit is contained in:
Oliver Gorwits
2014-08-10 13:43:31 +01:00
parent 1fd473fd50
commit 2366738d54
4 changed files with 36 additions and 27 deletions

View File

@@ -9,7 +9,7 @@ use Role::Tiny;
use namespace::clean; use namespace::clean;
use App::Netdisco::JobQueue qw/jq_locked jq_getsome jq_lock/; use App::Netdisco::JobQueue qw/jq_locked jq_getsome jq_lock/;
use MCE::Util 'get_ncpu'; use MCE::Util ();
sub worker_begin { sub worker_begin {
my $self = shift; my $self = shift;
@@ -27,7 +27,7 @@ sub worker_begin {
if (scalar @jobs) { if (scalar @jobs) {
info sprintf "mgr (%s): found %s jobs booked to this processing node", info sprintf "mgr (%s): found %s jobs booked to this processing node",
$wid, scalar @jobs; $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" return debug "mgr ($wid): no need for manager... quitting"
if setting('workers')->{'no_manager'}; if setting('workers')->{'no_manager'};
# FIXME really the best strategy? my $num_slots =
my $num_slots = (MCE::Util::get_ncpu() * 2) - $self->{queue}->pending(); MCE::Util::_parse_max_workers( setting('workers')->{pollers} )
- $self->{queue}->pending();
while (1) { while (1) {
debug "mgr ($wid): getting potential jobs for $num_slots workers"; debug "mgr ($wid): getting potential jobs for $num_slots workers";
@@ -55,7 +56,7 @@ sub worker_body {
$wid, $job->id; $wid, $job->id;
# copy job to local queue # copy job to local queue
$self->{queue}->enqueue($job); # FIXME priority and freeze $self->{queue}->enqueue($job);
} }
debug "mgr ($wid): sleeping now..."; debug "mgr ($wid): sleeping now...";

View File

@@ -29,10 +29,18 @@ sub jq_getsome {
my $rs = schema('netdisco')->resultset('Admin') my $rs = schema('netdisco')->resultset('Admin')
->search( ->search(
{status => 'queued'}, {status => 'queued', action => { -in => setting('job_prio')->{high} } },
{order_by => 'random()', rows => ($num_slots || 1)}, {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) { while (my $job = $rs->next) {
push @returned, schema('daemon')->resultset('Admin') push @returned, schema('daemon')->resultset('Admin')
->new_result({ $job->get_columns }); ->new_result({ $job->get_columns });

View File

@@ -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 { ajax "/ajax/control/admin/$action" => require_role admin => sub {
add_job($action, param('device'), param('extra')); add_job($action, param('device'), param('extra'));
}; };

View File

@@ -193,26 +193,24 @@ dns:
# expire: # expire:
# when: '20 23 * * *' # when: '20 23 * * *'
job_types: job_prio:
discoverall: Poller high:
discover: Poller - location
arpwalk: Poller - contact
arpnip: Poller - portcontrol
macwalk: Poller - portname
macsuck: Poller - vlan
nbtwalk: Poller - power
nbtstat: Poller normal:
expire: Poller - discoverall
location: Interactive - discover
contact: Interactive - arpwalk
portcontrol: Interactive - arpnip
portname: Interactive - macwalk
vlan: Interactive - macsuck
power: Interactive - nbtwalk
- nbtstat
job_type_keys: - expire
Poller: pollers
Interactive: interactives
# --------------- # ---------------
# GraphViz Export # GraphViz Export