def doFindNewSupplier(self, *args, **kwargs): """ Action method. """ if _Debug: lg.out(_DebugLevel, 'fire_hire.doFindNewSupplier') position_for_new_supplier = None for pos in range(settings.getSuppliersNumberDesired()): if pos in self.hire_list: continue supplier_idurl = contactsdb.supplier(pos) if not supplier_idurl: lg.info('found empty supplier at position %d and going to find new supplier on that position' % pos) position_for_new_supplier = pos break if supplier_idurl in self.dismiss_list: lg.info('going to find new supplier on existing position %d to replace supplier %s' % ( pos, supplier_idurl, )) position_for_new_supplier = pos break if position_for_new_supplier is None: lg.err('did not found position for new supplier') self.automat('search-failed') return self.hire_list.append(position_for_new_supplier) supplier_finder.A( 'start', family_position=position_for_new_supplier, ecc_map=eccmap.Current().name, family_snapshot=contactsdb.suppliers(), )
def doFindNewSupplier(self, *args, **kwargs): """ Action method. """ if _Debug: lg.out( _DebugLevel, 'fire_hire.doFindNewSupplier desired_suppliers=%d current_suppliers=%r' % (settings.getSuppliersNumberDesired(), contactsdb.suppliers())) from p2p import network_connector if network_connector.A().state != 'CONNECTED': if _Debug: lg.out( _DebugLevel, ' network_connector is not CONNECTED at the moment, SKIP' ) self.automat('search-failed') return position_for_new_supplier = None for pos in range(settings.getSuppliersNumberDesired()): if pos in self.hire_list: continue supplier_idurl = contactsdb.supplier(pos) if not supplier_idurl: lg.info( 'found empty supplier at position %d and going to find new supplier on that position' % pos) position_for_new_supplier = pos break if id_url.is_in(supplier_idurl, self.dismiss_list, as_field=False): lg.info( 'going to find new supplier on existing position %d to replace supplier %s' % ( pos, supplier_idurl, )) position_for_new_supplier = pos break if position_for_new_supplier is None: lg.err('did not found position for new supplier') self.automat('search-failed') return from customer import supplier_finder for idurl_txt in strng.to_text(config.conf().getData( 'services/employer/candidates')).split(','): if idurl_txt.strip(): supplier_finder.AddSupplierToHire(idurl_txt) self.hire_list.append(position_for_new_supplier) supplier_finder.A( 'start', family_position=position_for_new_supplier, ecc_map=eccmap.Current().name, family_snapshot=id_url.to_bin_list(contactsdb.suppliers()), )
def A(self, event, arg): #---READY--- if self.state == 'READY': if (event == 'restart' or (event == 'instant' and self.NeedRestart) ) and not (self.isConfigChanged(arg) and self.isExistSomeSuppliers(arg)): self.state = 'DECISION?' self.NeedRestart = False self.doDecideToDismiss(arg) elif ( event == 'restart' or (event == 'instant' and self.NeedRestart) ) and self.isConfigChanged(arg) and self.isExistSomeSuppliers(arg): self.state = 'SUPPLIERS?' self.NeedRestart = False self.doSaveConfig(arg) self.doConnectSuppliers(arg) #---DECISION?--- elif self.state == 'DECISION?': if event == 'made-decision' and self.isSomeoneToDismiss( arg) and not self.isMoreNeeded(arg): self.state = 'FIRE_MANY' self.doRememberSuppliers(arg) self.doRemoveSuppliers(arg) self.doDisconnectSuppliers(arg) elif event == 'restart': self.NeedRestart = True elif event == 'made-decision' and not self.isMoreNeeded( arg) and not self.isSomeoneToDismiss(arg): self.state = 'READY' self.doNotifyFinished(arg) elif event == 'made-decision' and self.isMoreNeeded(arg): self.state = 'HIRE_ONE' self.doRememberSuppliers(arg) supplier_finder.A('start') #---HIRE_ONE--- elif self.state == 'HIRE_ONE': if event == 'restart': self.NeedRestart = True elif event == 'supplier-connected' and not self.isStillNeeded( arg) and self.isSomeoneToDismiss(arg): self.state = 'FIRE_MANY' self.doSubstituteSupplier(arg) self.doDisconnectSuppliers(arg) elif event == 'supplier-connected' and not self.isStillNeeded( arg) and not self.isSomeoneToDismiss(arg): self.state = 'READY' self.doSubstituteSupplier(arg) self.doNotifySuppliersChanged(arg) elif event == 'supplier-connected' and self.isStillNeeded(arg): self.doSubstituteSupplier(arg) supplier_finder.A('start') elif event == 'search-failed' and not self.isSomeoneToDismiss(arg): self.state = 'READY' self.doScheduleNextRestart(arg) elif event == 'search-failed' and self.isSomeoneToDismiss(arg): self.state = 'FIRE_MANY' self.doDisconnectSuppliers(arg) self.doRemoveSuppliers(arg) self.doScheduleNextRestart(arg) #---FIRE_MANY--- elif self.state == 'FIRE_MANY': if event == 'timer-15sec': self.state = 'READY' self.doCloseConnectors(arg) self.doClearDismissList(arg) self.doNotifySuppliersChanged(arg) elif event == 'supplier-state-changed' and not self.isAllDismissed( arg): self.doCloseConnector(arg) elif event == 'restart': self.NeedRestart = True elif event == 'supplier-state-changed' and self.isAllDismissed( arg): self.state = 'READY' self.doCloseConnector(arg) self.doClearDismissList(arg) self.doNotifySuppliersChanged(arg) #---SUPPLIERS?--- elif self.state == 'SUPPLIERS?': if event == 'restart': self.NeedRestart = True elif (event == 'supplier-state-changed' and self.isAllReady(arg)) or event == 'timer-15sec': self.state = 'DECISION?' self.doDecideToDismiss(arg) #---AT_STARTUP--- elif self.state == 'AT_STARTUP': if event == 'init': self.state = 'READY' self.NeedRestart = False return None