From bb67f1aaec9f6f1709c16073379b8037b63ff70c Mon Sep 17 00:00:00 2001 From: Guillaume Rousse Date: Tue, 26 Jun 2012 18:14:51 +0200 Subject: [PATCH] handle --wait option directly from executable (#1701) --- etc/agent.cfg | 2 -- fusioninventory-agent | 18 ++++++++++++------ lib/FusionInventory/Agent/Config.pm | 1 - lib/FusionInventory/Agent/Scheduler.pm | 17 ----------------- 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/etc/agent.cfg b/etc/agent.cfg index 8494b0b857..d84d8bcf84 100644 --- a/etc/agent.cfg +++ b/etc/agent.cfg @@ -30,8 +30,6 @@ # maximum initial delay before first target, in seconds delaytime = 3600 -# maximum delay between each targets, in seconds -wait = # do not contact the target before next scheduled time lazy = 0 diff --git a/fusioninventory-agent b/fusioninventory-agent index 1eb4c61334..da74a1eec5 100755 --- a/fusioninventory-agent +++ b/fusioninventory-agent @@ -104,6 +104,11 @@ if ($options->{'list-tasks'}) { exit 0; } +if ($options->{wait}) { + my $time = int rand($options->{wait}); + sleep $time; +} + eval { $agent->init(options => $options); $agent->run(); @@ -134,7 +139,6 @@ B [options] [--server server|--local directory|--sdout] Target scheduling options --delaytime=DURATION maximum initial delay before first target, in seconds (3600) - -w --wait=DURATION maximum delay between each target, in seconds --lazy do not contact the target before next scheduled time Task selection options @@ -180,6 +184,7 @@ B [options] [--server server|--local directory|--sdout] --conf-file=FILE configuration file Execution mode options + -w --wait=DURATION maximum delay before execution, in seconds -d --daemon run the agent as a daemon (false) --no-fork don't fork in background (false) --debug debug mode (false) @@ -330,11 +335,6 @@ between LIMIT / 2 and LIMIT seconds. This setting is ignored for server targets after the initial contact, in favor of server-specified parameter (PROLOG_FREQ). -=item B<-w> I, B<--wait>=I - -Set a delay between each targets, whose value is computed randomly between 0 -and LIMIT seconds. - =item B<--lazy> Do not contact the target before next scheduled time. @@ -539,6 +539,12 @@ none: don't read any configuration =over +=item B<-w> I, B<--wait>=I + +Wait a random delay whose value is computed randomly between 0 and LIMIT +seconds, before execution. This is useful when execution is triggered from some +kind of system scheduling on multiple clients, to spread the server load. + =item B<-d>, B<--daemon> Run the agent as a daemon. diff --git a/lib/FusionInventory/Agent/Config.pm b/lib/FusionInventory/Agent/Config.pm index 4ac9b812fb..ee49231fa3 100644 --- a/lib/FusionInventory/Agent/Config.pm +++ b/lib/FusionInventory/Agent/Config.pm @@ -40,7 +40,6 @@ my $default = { 'tag' => undef, 'timeout' => undef, 'user' => undef, - 'wait' => undef, # deprecated options 'no-ocsdeploy' => undef, 'no-inventory' => undef, diff --git a/lib/FusionInventory/Agent/Scheduler.pm b/lib/FusionInventory/Agent/Scheduler.pm index 00bc8a0425..12e8417ad1 100644 --- a/lib/FusionInventory/Agent/Scheduler.pm +++ b/lib/FusionInventory/Agent/Scheduler.pm @@ -12,7 +12,6 @@ sub new { logger => $params{logger} || FusionInventory::Agent::Logger->new(), lazy => $params{lazy}, - wait => $params{wait}, background => $params{background}, targets => [] }; @@ -62,17 +61,6 @@ sub getNextTarget { } } - if ($self->{wait}) { - # return next target after waiting for a random delay - my $time = int rand($self->{wait}); - $logger->info( - "[scheduler] sleeping for $time second(s) because of the wait " . - "parameter" - ); - sleep $time; - return $target; - } - # return next target immediatly return $target; } @@ -112,11 +100,6 @@ the logger object to use (default: a new stderr logger) a flag to ensure targets whose next scheduled execution date has not been reached yet will get ignored. Only useful when I flag is not set. -=item I - -a number of second to wait before returning each target. Only useful when -I flag is not set. - =item I a flag to set if the agent is running as a resident program, aka a daemon in