def spawn_agent(self, state, desc, static_name=None, **kwargs): """ This method is used by the agency to spawn agents. The desc parameter can actually be a descriptor to be save into database, or just it's identifier, it which case it should be created and saved with default values. """ if not IDescriptor.providedBy(desc): factory = applications.lookup_descriptor(desc) if factory is None: msg = ('No descriptor factory found for agent %r' % desc) raise error.FeatError(msg) desc = factory() f = self.save_document(desc) f.add_callback(self.start_agent, static_name=static_name, **kwargs) f.add_errback(self._spawn_agent_failed, desc, alert_name=static_name) return f
def initiate(self, state, doc_id, allocation_id, kwargs=dict(), static_name=None): if IDescriptor.providedBy(doc_id): doc_id = doc_id.doc_id assert isinstance(doc_id, (str, unicode)), "doc_id is %r" % (doc_id,) state.doc_id = doc_id state.descriptor = None state.allocation_id = allocation_id state.static_name = static_name f = fiber.succeed() f.add_callback(fiber.drop_param, self._fetch_descriptor) f.add_callback(fiber.drop_param, self._check_requirements) f.add_callback(fiber.drop_param, self._validate_allocation) f.add_callback(self._update_descriptor) f.add_callback(state.agent.medium_start_agent, **kwargs) f.add_callback(recipient.IRecipient) f.add_callback(self._establish_partnership) return f