random() and LIMIT the number of daemon jobs requested from Netdisco queue

This commit is contained in:
Oliver Gorwits
2013-02-23 23:53:59 +00:00
parent 992086084b
commit 6507ac22a6
4 changed files with 18 additions and 3 deletions

View File

@@ -1,3 +1,9 @@
2.005000_003 - 2013-02-24
[ENHANCEMENTS]
* random() and LIMIT the number of daemon jobs requested from Netdisco queue
2.005000_002 - 2013-02-10 2.005000_002 - 2013-02-10
[ENHANCEMENTS] [ENHANCEMENTS]

View File

@@ -51,4 +51,4 @@ resources:
homepage: http://netdisco.org/ homepage: http://netdisco.org/
license: http://opensource.org/licenses/bsd-license.php license: http://opensource.org/licenses/bsd-license.php
repository: git://netdisco.git.sourceforge.net/gitroot/netdisco/netdisco-ng repository: git://netdisco.git.sourceforge.net/gitroot/netdisco/netdisco-ng
version: 2.005000_001 version: 2.005000_002

View File

@@ -56,6 +56,11 @@ sub build_tasks_list {
return $tasks; return $tasks;
} }
# includes the Manager worker
sub num_workers {
return (setting('daemon_pollers') + setting('daemon_interactives'));
}
sub worker_factory { sub worker_factory {
my $role = shift; my $role = shift;
return sub { return sub {

View File

@@ -32,10 +32,14 @@ sub worker_begin {
sub worker_body { sub worker_body {
my $self = shift; my $self = shift;
my $num_slots = $self->do('num_workers') - 1;
# get all pending jobs # get some pending jobs
my $rs = schema('netdisco')->resultset('Admin') my $rs = schema('netdisco')->resultset('Admin')
->search({status => 'queued'}); ->search(
{status => 'queued'},
{order_by => 'random()', rows => $num_slots},
);
while (1) { while (1) {
while (my $job = $rs->next) { while (my $job = $rs->next) {