Skip to content

Commit

Permalink
handle --wait option directly from executable (#1701)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillomovitch committed Jun 26, 2012
1 parent e7c45c6 commit bb67f1a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
2 changes: 0 additions & 2 deletions etc/agent.cfg
Expand Up @@ -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

Expand Down
18 changes: 12 additions & 6 deletions fusioninventory-agent
Expand Up @@ -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();
Expand Down Expand Up @@ -134,7 +139,6 @@ B<fusioninventory-agent> [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
Expand Down Expand Up @@ -180,6 +184,7 @@ B<fusioninventory-agent> [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)
Expand Down Expand Up @@ -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<LIMIT>, B<--wait>=I<LIMIT>
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.
Expand Down Expand Up @@ -539,6 +539,12 @@ none: don't read any configuration
=over
=item B<-w> I<LIMIT>, B<--wait>=I<LIMIT>
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.
Expand Down
1 change: 0 additions & 1 deletion lib/FusionInventory/Agent/Config.pm
Expand Up @@ -40,7 +40,6 @@ my $default = {
'tag' => undef,
'timeout' => undef,
'user' => undef,
'wait' => undef,
# deprecated options
'no-ocsdeploy' => undef,
'no-inventory' => undef,
Expand Down
17 changes: 0 additions & 17 deletions lib/FusionInventory/Agent/Scheduler.pm
Expand Up @@ -12,7 +12,6 @@ sub new {
logger => $params{logger} ||
FusionInventory::Agent::Logger->new(),
lazy => $params{lazy},
wait => $params{wait},
background => $params{background},
targets => []
};
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<background> flag is not set.
=item I<wait>
a number of second to wait before returning each target. Only useful when
I<background> flag is not set.
=item I<background>
a flag to set if the agent is running as a resident program, aka a daemon in
Expand Down

0 comments on commit bb67f1a

Please sign in to comment.