Skip to content

Commit

Permalink
B #3119: Hourly sched actions just execute one time
Browse files Browse the repository at this point in the history
* Change next_action to return the time for next_action
* Change XML query to use REPEAT
* Update the TIME if the value is lower than DONE
  • Loading branch information
Alejandro Huertas Herrero authored and Ruben S. Montero committed Mar 25, 2019
1 parent e33b8b0 commit c76377f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions include/ScheduledAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/include/VirtualMachinePoolXML.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 8 additions & 2 deletions src/scheduler/src/sched/Scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
Expand Down
16 changes: 9 additions & 7 deletions src/vm_template/ScheduledAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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] == '+' )
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -393,7 +395,7 @@ int SchedAction::next_action()

replace("TIME", action_time);

return 0;
return action_time;
}

/* --------------------------------------------------------------------- */
Expand Down Expand Up @@ -449,5 +451,5 @@ int SchedAction::next_action()

replace("TIME", action_time);

return 0;
return action_time;
}

0 comments on commit c76377f

Please sign in to comment.