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 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...";

View File

@@ -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 });

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 {
add_job($action, param('device'), param('extra'));
};

View File

@@ -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