@@ -422,15 +422,18 @@ def converge(self, databag):
422422 return databag
423423
424424 def destroy (self ):
425- subtasks = []
425+ node_tasks , layer_tasks , chef_tasks = [], [], []
426+ # create subtasks to terminate all nodes in parallel
427+ all_layers = self .layer_set .all ()
428+ node_tasks .extend ([ layer .destroy ()[0 ] for layer in all_layers ])
429+ layer_tasks .extend ([ layer .destroy ()[1 ] for layer in all_layers ])
426430 # call a celery task to update the formation data bag
427431 if settings .CHEF_ENABLED :
428- subtasks .extend ([controller .destroy_formation .s (self .id )]) # @UndefinedVariable
429- # create subtasks to terminate all nodes in parallel
430- subtasks .extend ([ layer .destroy () for layer in self .layer_set .all () ])
431- job = group (* subtasks )
432- if job :
433- job .apply_async ().join () # block for termination
432+ chef_tasks .extend ([controller .destroy_formation .s (self .id )]) # @UndefinedVariable
433+ # block for tasks by group
434+ group (* node_tasks ).apply_async ().join ()
435+ group (* layer_tasks ).apply_async ().join ()
436+ group (* chef_tasks ).apply_async ().join ()
434437
435438
436439@python_2_unicode_compatible
@@ -472,13 +475,13 @@ def destroy(self):
472475 subtasks = []
473476 # create subtasks to terminate all nodes in parallel
474477 subtasks .extend ([ node .terminate () for node in self .node_set .all () ])
475- job = group (* subtasks )
476- job .apply_async ().join () # block for termination
478+ node_tasks = group (* subtasks )
477479 # purge other hosting provider infrastructure
478480 name = "{0}-{1}" .format (self .formation .id , self .id )
479- tasks .destroy_layer .delay (name ,
480- self .flavor .provider .creds .copy (),
481- self .flavor .params .copy ()).wait () # block
481+ args = (name , self .flavor .provider .creds .copy (),
482+ self .flavor .params .copy ())
483+ layer_tasks = group (* [tasks .destroy_layer .subtask (args )])
484+ return node_tasks , layer_tasks
482485
483486
484487@python_2_unicode_compatible
0 commit comments