コード例 #1
0
 def reply(payloadEnvelope: PayloadEnvelope):
     payloadEnvelope.filt = responseFilt
     d: Deferred = payloadEnvelope.toVortexMsgDefer()
     d.addCallback(sendResponse)
     return d
コード例 #2
0
    def _processInThread(self, payloadEnvelope: PayloadEnvelope,
                         vortexUuid: str,
                         sendResponse: Callable[[Union[VortexMsgList, bytes]],
                                                None], **kwargs):

        # Execute preprocess functions
        if self.preProcess(payloadEnvelope, vortexUuid, **kwargs) != None:
            return

        # Create reply payload replyFilt

        replyFilt = copy(self._payloadFilter)
        if payloadEnvelope.filt:
            replyFilt.update(payloadEnvelope.filt)

        # Get data from the payload
        phId = payloadEnvelope.filt.get(plIdKey)
        delete = payloadEnvelope.filt.get(plDeleteKey, False)

        # Setup variables to populate
        replyPayloadEnvelope: PayloadEnvelope = None
        action = None

        tuples = []
        if payloadEnvelope.encodedPayload:
            tuples = payloadEnvelope.decodePayload().tuples

        session = self._getSession()

        # Execute the action
        try:
            if delete == True:
                action = self.DELETE
                replyPayloadEnvelope = self._delete(session, tuples, phId,
                                                    payloadEnvelope.filt)

            elif len(tuples):
                action = self.UPDATE
                replyPayloadEnvelope = self._update(session, tuples,
                                                    payloadEnvelope.filt)

            elif phId != None:
                action = self.QUERY
                replyPayloadEnvelope = self._retrieve(session, phId,
                                                      payloadEnvelope.filt)

            elif len(tuples) == 0:
                action = self.CREATE
                replyPayloadEnvelope = self._create(session,
                                                    payloadEnvelope.filt)

            else:
                session.close()
                raise Exception("Invalid ORM CRUD parameter state")

        except Exception as e:
            replyPayloadEnvelope = PayloadEnvelope(result=str(e),
                                                   filt=replyFilt)
            sendResponse(replyPayloadEnvelope.toVortexMsg())
            try:
                session.rollback()
            except:
                pass
            session.close()
            raise

        # Prefer reply filt, if not combine our accpt filt with the filt we were sent

        # Ensure any delegates are playing nice with the result
        if action in (self.DELETE,
                      self.UPDATE) and replyPayloadEnvelope.result is None:
            replyPayloadEnvelope.result = True

        replyPayloadEnvelope.filt = replyFilt
        sendResponse(replyPayloadEnvelope.toVortexMsg())

        # Execute the post process function
        self.postProcess(action, payloadEnvelope.filt, vortexUuid)
        session.commit()
        session.close()