#NEWLINE# @ register_bounce_method ( 'crossover' ) #NEWLINE# def crossover_bounce( new_config , new_app_running , happy_new_tasks , old_app_live_happy_tasks , old_app_live_unhappy_tasks ) : #NEWLINE# #INDENT# 'Starts a new app if necessary; slowly kills old apps as instances of the new app become happy.\n\n    See the docstring for brutal_bounce() for parameters and return value.\n    ' #NEWLINE# if ( not new_app_running ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'create_app' : True , #NEWLINE# 'tasks_to_drain' : set ( ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# happy_count = len ( happy_new_tasks ) #NEWLINE# needed_count = max ( ( old_app_live_unhappy_tasks [ 'instances' ] - happy_count ) , 0 ) #NEWLINE# old_tasks = [ ] #NEWLINE# for ( app , tasks ) in old_app_live_happy_tasks . items ( ) : #NEWLINE# #INDENT# for task in tasks : #NEWLINE# #INDENT# old_tasks . append ( task ) #NEWLINE# #UNINDENT# #UNINDENT# for ( app , tasks ) in old_app_live_unhappy_tasks . items ( ) : #NEWLINE# #INDENT# for task in tasks : #NEWLINE# #INDENT# old_tasks . append ( task ) #NEWLINE# #UNINDENT# #UNINDENT# return { #NEWLINE# #INDENT# 'create_app' : False , #NEWLINE# 'tasks_to_drain' : set ( set ( old_tasks [ needed_count : ] ) ) , #NEWLINE# #UNINDENT# }