def invoke(message): try: key = self.generateMessageUID(message) if key in invoked: return invoked.add(key) except AttributeError: pass line = getattr(message, 'line', None) if (line and line.processing_node != -1 or self._getExecutableMessageSet(activity_tool, db, [message])): # Try to invoke the message - what happens if invoke calls flushActivity ?? with ActivityRuntimeEnvironment(message): activity_tool.invoke(message) if message.getExecutionState() != MESSAGE_EXECUTED: raise ActivityFlushError('Could not invoke %s on %s' % (message.method_id, path)) else: raise ActivityFlushError('Could not validate %s on %s' % (message.method_id, path))
def invoke(message): try: key = self.generateMessageUID(message) if key in invoked: return invoked.add(key) except AttributeError: pass line = getattr(message, 'line', None) validate_value = VALID if line and line.processing_node != -1 else \ message.validate(self, activity_tool) if validate_value == VALID: # Try to invoke the message - what happens if invoke calls flushActivity ?? with ActivityRuntimeEnvironment(message): activity_tool.invoke(message) if message.getExecutionState() != MESSAGE_EXECUTED: raise ActivityFlushError('Could not invoke %s on %s' % (message.method_id, path)) elif validate_value is INVALID_PATH: raise ActivityFlushError('The document %s does not exist' % path) else: raise ActivityFlushError('Could not validate %s on %s' % (message.method_id, path))
def dequeueMessage(self, activity_tool, processing_node): message_list, group_method_id, uid_to_duplicate_uid_list_dict = \ self.getProcessableMessageList(activity_tool, processing_node) if message_list: # Remove group_id parameter from group_method_id if group_method_id is not None: group_method_id = group_method_id.split('\0')[0] if group_method_id not in (None, ""): method = activity_tool.invokeGroup args = (group_method_id, message_list, self.__class__.__name__, hasattr(self, 'generateMessageUID')) activity_runtime_environment = ActivityRuntimeEnvironment(None) else: method = activity_tool.invoke message = message_list[0] args = (message, ) activity_runtime_environment = ActivityRuntimeEnvironment( message) # Commit right before executing messages. # As MySQL transaction does not start exactly at the same time as ZODB # transactions but a bit later, messages available might be called # on objects which are not available - or available in an old # version - to ZODB connector. # So all connectors must be committed now that we have selected # everything needed from MySQL to get a fresh view of ZODB objects. transaction.commit() transaction.begin() # Try to invoke try: with activity_runtime_environment: method(*args) # Abort if at least 1 message failed. On next tic, only those that # succeeded will be selected because their at_date won't have been # increased. for m in message_list: if m.getExecutionState() == MESSAGE_NOT_EXECUTED: raise _DequeueMessageException transaction.commit() except: exc_info = sys.exc_info() if exc_info[1] is not _DequeueMessageException: self._log( WARNING, 'Exception raised when invoking messages (uid, path, method_id) %r' % [(m.uid, m.object_path, m.method_id) for m in message_list]) for m in message_list: m.setExecutionState(MESSAGE_NOT_EXECUTED, exc_info, log=False) self._abort() exc_info = message_list[0].exc_info if exc_info: try: # Register it again. with activity_runtime_environment: cancel = message.on_error_callback(*exc_info) del exc_info, message.exc_info transaction.commit() if cancel: message.setExecutionState(MESSAGE_EXECUTED) except: self._log( WARNING, 'Exception raised when processing error callbacks') message.setExecutionState(MESSAGE_NOT_EXECUTED) self._abort() self.finalizeMessageExecution(activity_tool, message_list, uid_to_duplicate_uid_list_dict) transaction.commit() return not message_list