Skip to content

Commit

Permalink
fix: Manage to reschedule target tasks after they had been all manual…
Browse files Browse the repository at this point in the history
…ly triggered via httpd interface
  • Loading branch information
g-bougard committed Jan 23, 2025
1 parent 903cf07 commit e862306
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/GLPI/Agent/Daemon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ sub run {
# Leave immediately if we passed in terminate method
last if $self->{_terminate};

# Reschedule if required
if ($event->taskrun && $event->get('reschedule')) {
# First set rundate to now, than reset next run date
$target->setNextRunDateFromNow();
$target->resetNextRunDate();

if ($logger) {
my $date = $target->getFormatedNextRunDate();
my $id = $target->id();
my $name = $target->getName();
$logger->info("target $id: next run: $date - $name");
}
}

# We should run service optimization after all targets can be run
$self->{_run_optimization} = scalar($self->getTargets());

Expand Down
6 changes: 5 additions & 1 deletion lib/GLPI/Agent/Event.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ sub new {
} elsif ($params{taskrun} && $params{taskrun} =~ /^yes|1$/i) {
# Run task request eventually following a runnow event
$self = {
_taskrun => 1,
_taskrun => 1,
_name => "run",
_task => $params{task} // '',
_delay => $params{delay} // 0,
_httpd => 1,
_params => {
# Support parameter to reset target next rundate on task run
reschedule => $params{reschedule} // 0,
}
};
# Store any other supported params
if ($params{task} && $params{task} eq "inventory") {
Expand Down
9 changes: 8 additions & 1 deletion lib/GLPI/Agent/Target.pm
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,11 @@ sub triggerRunTasksNow {

my %plannedTasks = map { lc($_) => 1 } @{$self->{tasks}};
my $task = $event->task;
my @tasks = $task && $task eq "all" ? @{$self->{tasks}} : split(/,+/, $task);
my $all = $task && $task eq "all" ? 1 : 0;
my @tasks = $all ? @{$self->{tasks}} : split(/,+/, $task);
my $reschedule_index = $all ? scalar(@tasks) : 0;
foreach my $runtask (map { lc($_) } @tasks) {
$reschedule_index--;
next unless $plannedTasks{$runtask};

my %event = (
Expand All @@ -193,6 +196,10 @@ sub triggerRunTasksNow {
delay => 0,
);

# permit to reschedule on last task run
$event{reschedule} = 1
if $all && $reschedule_index == 0;

# Add any supported params
if ($runtask eq "inventory") {
my $full = $event->get("full");
Expand Down

0 comments on commit e862306

Please sign in to comment.