Commit 57182f13 authored by Thomas Lavocat's avatar Thomas Lavocat
Browse files

Allow group to execute action before terminaison

Work needs to be done before declaring wanting to transit between
running and done states. This work is, asking the underlying transport
to kill its instances and clean stuff on the remote computers. Thus,
declaring that the work is done is wrong. The work is done when this
step is done.

To enable this asynchonous possibility a task can now ask the execution
of a callback function when a changing state is possible. It's a way to
execute an out-of-workflow operation still inside the state-machine
parent a945080a
......@@ -66,9 +66,12 @@ class Group(Task):
def terminate_task(self) :
def kill_group(self) :
self.framework.erebor.on_network_shutdown(self.ID, self.notify_done)
self.framework.delete_network(self.ID, "0", self.ID, self.root_r,
def notify_done(self, data) :
......@@ -15,6 +15,7 @@ class Task:
self.listen_on = []
# for transitions
self.dependant_transitions = dict()
self.waiting_callback_on_possible_transition = dict()
self.waiting_transitions = []
self.trigger_transitions = dict()
self.timer = None
......@@ -97,6 +98,13 @@ class Task:
if transition in self.waiting_transitions :
# check code that need to be executed when a transition is
# possible
if transition in self.waiting_callback_on_possible_transition :
callback = self.waiting_callback_on_possible_transition[transition]
del self.waiting_callback_on_possible_transition[transition]
# For triggers
# Propagate the foreign transition
transition_to_remove = []
......@@ -116,6 +124,33 @@ class Task:
for transition in transition_to_remove :
def execute_when_transition_transition_possible(self, transition, callback) :
Will execute the given callback when the transition is possible.
Used when a task needs to do special work before entering a transition
to a special state.
Used especially for groups : When a group needs to terminate, some
(maybe time consuming and asynchronous) code
needs to be executed before arriving to the DONE state.
if ( transition is consts.IDLE_INIT or
transition is consts.IDDLE_CANCEL or
transition is consts.INIT_RUNNING or
transition is consts.INIT_ERROR or
transition is consts.INIT_CANCELED or
transition is consts.RUNNING_DONE or
transition is consts.RUNNING_ERROR or
transition is consts.RUNNING_TIMEOUT or
transition is consts.RUNNING_CANCELED) :
if self.check_dependencies_for_transition(transition) :
else :
else :
print("invalid transition asked")
def request_transition(self, transition) :
will try to apply the asked transition to the current task, if a
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment