diff --git a/include/ScheduledAction.h b/include/ScheduledAction.h index 96ca4fff7e9..8e058897dcc 100644 --- a/include/ScheduledAction.h +++ b/include/ScheduledAction.h @@ -106,9 +106,9 @@ class SchedAction: public VirtualMachineAttribute /** * Compute the next action, updating the TIME attribute for this action - * @return -1 if action ended 0 otherwise + * @return time for next action, if ended or error -1 */ - int next_action(); + time_t next_action(); }; /** diff --git a/src/scheduler/include/VirtualMachinePoolXML.h b/src/scheduler/include/VirtualMachinePoolXML.h index 2337c7bcdbb..6be45929c10 100644 --- a/src/scheduler/include/VirtualMachinePoolXML.h +++ b/src/scheduler/include/VirtualMachinePoolXML.h @@ -166,7 +166,7 @@ class VirtualMachineActionsPoolXML : public VirtualMachinePoolXML ostringstream oss; oss << "/VM_POOL/VM/USER_TEMPLATE/SCHED_ACTION[(TIME < " << time(0) - << " and not(DONE > 0)) or ( TIME[starts-with(text(),\"+\")] and not(DONE>0) ) ]/../.."; + << " and (not(DONE > 0) or boolean(REPEAT))) or ( TIME[starts-with(text(),\"+\")] and not(DONE>0) ) ]/../.."; return get_nodes(oss.str().c_str(), content); } diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 5cc1930c531..3f6c9e0066b 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -1759,11 +1759,17 @@ int Scheduler::do_scheduled_actions() if (rc == 0) { + time_t done_time = time(0); + time_t next_time; + (*action)->remove("MESSAGE"); - (*action)->replace("DONE", time(0)); + (*action)->replace("DONE", done_time); - (*action)->next_action(); + do + { + next_time = (*action)->next_action(); + } while ( next_time < done_time && next_time != -1 ); oss << "Success."; } diff --git a/src/vm_template/ScheduledAction.cc b/src/vm_template/ScheduledAction.cc index 9840fc5b47d..5e4b518dec4 100644 --- a/src/vm_template/ScheduledAction.cc +++ b/src/vm_template/ScheduledAction.cc @@ -296,11 +296,12 @@ static int days_in_period(SchedAction::Repeat& r, int month, int year) bool SchedAction::is_due(time_t stime) { time_t action_time, done_time, origin = 0; + int repeat; std::istringstream iss; - bool has_done = vector_value("DONE", done_time) == 0; - + bool has_done = vector_value("DONE", done_time) == 0; + bool has_repeat = vector_value("REPEAT", repeat) == 0; std::string action_time_s = vector_value("TIME"); if ( action_time_s[0] == '+' ) @@ -320,13 +321,14 @@ bool SchedAction::is_due(time_t stime) action_time += origin; - return ((!has_done || done_time < action_time) && action_time < time(0)); + return ((!has_done || done_time < action_time || has_repeat) + && action_time < time(0)); } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int SchedAction::next_action() +time_t SchedAction::next_action() { Repeat r; EndOn eo; @@ -358,7 +360,7 @@ int SchedAction::next_action() int end_value; int rc = vector_value("END_VALUE", end_value); - if ( rc == -1 ) + if ( rc == -1 && eo != NEVER) { return -1; } @@ -393,7 +395,7 @@ int SchedAction::next_action() replace("TIME", action_time); - return 0; + return action_time; } /* --------------------------------------------------------------------- */ @@ -449,5 +451,5 @@ int SchedAction::next_action() replace("TIME", action_time); - return 0; + return action_time; }