Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

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
transitions.
parent a945080a
......@@ -66,9 +66,12 @@ class Group(Task):
self.request_transition(self.state+consts.ERROR)
def terminate_task(self) :
self.execute_when_transition_transition_possible(self.state+consts.DONE,
self.kill_group)
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,
self.root_n)
def notify_done(self, data) :
self.request_transition(self.state+consts.DONE)
......@@ -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 :
self.waiting_transitions.remove(transition)
self.request_transition(transition)
# check code that need to be executed when a transition is
# possible
print(self.waiting_callback_on_possible_transition)
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]
callback()
# For triggers
# Propagate the foreign transition
transition_to_remove = []
......@@ -116,6 +124,33 @@ class Task:
for transition in transition_to_remove :
self.request_transition(transition)
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) :
callback()
else :
self.waiting_callback_on_possible_transition[transition]=callback
else :
print("invalid transition asked")
def request_transition(self, transition) :
"""
will try to apply the asked transition to the current task, if a
......
Markdown is supported
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