#NEWLINE# @ defer . deferredGenerator #NEWLINE# def assimilateProcess( self , information ) : #NEWLINE# #INDENT# 'Naive assimilation method. This should work for standard single\n           instance applications, it will attempt to work with multi-instance\n           applications as well. You should consider overriding this in an\n           ApplicationPlugin if you need more advanced strategies.\n\n           This is used by the ``services.application`` module to assimilate\n           rogue application instances.\n\n           This makes a best guess of which instance this should be assigned\n           too.\n\n           @param information (dict) "result of self.findPid"\n              - required key "pid": (int) > 0\n              - optional key "name": (str) self.name == name\n              - optional key "label": (str) bind to this instance\n              - optional key "version": (str) set version or promote version\n\n           NOTES\n              ``information[\'label\']`` if the instance is running already\n                  assimilation will fail\n\n           @callback (instance of droned.models.app.AppInstance or None)\n           @return (instance of defer.Deferred)\n        ' #NEWLINE# result = None #NEWLINE# pid = information . get ( 'pid' , 0 ) #NEWLINE# name = information . get ( 'name' , information . get ( 'DRONED_APPLICATION' , self . name ) ) #NEWLINE# version = information . get ( 'version' , information . get ( 'DRONED_VERSION' , None ) ) #NEWLINE# label = information . get ( 'label' , information . get ( 'DRONED_LABEL' , None ) ) #NEWLINE# try : #NEWLINE# #INDENT# assert pid #NEWLINE# assert App . exists ( name ) #NEWLINE# if label : #NEWLINE# #INDENT# thisInst = self . getInstance ( label ) #NEWLINE# assert ( not thisInst . running ) #NEWLINE# if ( bool ( version ) and ( thisInst . version != version ) ) : #NEWLINE# #INDENT# thisInst = self . setVersion ( label , version ) #NEWLINE# #UNINDENT# thisInst . pid = pid #NEWLINE# result = thisInst #NEWLINE# raise Exception ( 'assimilated process' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# options = set ( ) #NEWLINE# for ai in App ( name ) . localappinstances : #NEWLINE# #INDENT# if ai . running : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# options . add ( ai ) #NEWLINE# #UNINDENT# if bool ( version ) : #NEWLINE# #INDENT# for opt in options : #NEWLINE# #INDENT# if ( opt . version == version ) : #NEWLINE# #INDENT# opt . pid = pid #NEWLINE# result = opt #NEWLINE# raise Exception ( 'assimilated process' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# thisInst = sorted ( [ i for i in options if ( not i . running ) ] ) [ 0 ] #NEWLINE# if ( bool ( version ) and ( information . version != version ) ) : #NEWLINE# #INDENT# thisInst = self . setVersion ( thisInst . label , version ) #NEWLINE# #UNINDENT# thisInst . pid = pid #NEWLINE# result = thisInst #NEWLINE# raise Exception ( 'assimilated process' ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# d = defer . Deferred ( ) #NEWLINE# self . reactor . callLater ( 0.1 , d . callback , result ) #NEWLINE# wfd = defer . waitForDeferred ( d ) #NEWLINE# ( yield wfd ) #NEWLINE# result = wfd . getResult ( ) #NEWLINE# ( yield result )