コード例 #1
0
    async def _send_event(self, request):
        event_proto = request.event
        event = BaseEvent(
            key=event_proto.key,
            value=event_proto.value,
            event_type=None
            if event_proto.event_type == "" else event_proto.event_type,
            context=None if event_proto.context == "" else event_proto.context,
            namespace=None
            if event_proto.namespace == "" else event_proto.namespace)
        uuid = request.uuid
        key = event.key
        namespace = event.namespace
        # Lock conditions dict for get/check/update of key
        await self.lock.acquire()
        if self.notification_conditions.get((key, namespace)) is None:
            self.notification_conditions.update({((key, namespace),
                                                  asyncio.Condition())})
        # Release lock after check/update key of notification conditions dict
        self.lock.release()
        async with self.notification_conditions.get(
            (key, namespace)), self.write_condition:
            event: BaseEvent = self.storage.add_event(event, uuid)
            self.notification_conditions.get((key, namespace)).notify_all()
            self.write_condition.notify_all()

        result_event_proto = event_to_proto(event)
        return notification_service_pb2.SendEventsResponse(
            event=result_event_proto,
            return_code=notification_service_pb2.ReturnStatus.SUCCESS,
            return_msg='')
コード例 #2
0
 def sendEvent(self, request, context):
     try:
         return self._send_event(request)
     except Exception as e:
         print(e)
         traceback.print_stack()
         return notification_service_pb2.SendEventsResponse(
             return_code=str(notification_service_pb2.ReturnStatus.ERROR),
             return_msg=str(e))
コード例 #3
0
    async def _send_event(self, request):
        event_proto = request.event
        event = BaseEvent(key=event_proto.key,
                          value=event_proto.value,
                          event_type=event_proto.event_type)
        key = event.key
        # Lock conditions dict for get/check/update of key
        await self.lock.acquire()
        if self.notification_conditions.get(key) is None:
            self.notification_conditions.update({(key, asyncio.Condition())})
        # Release lock after check/update key of notification conditions dict
        self.lock.release()
        async with self.notification_conditions.get(key), self.write_condition:
            event: BaseEvent = self.storage.add_event(event)
            self.notification_conditions.get(key).notify_all()
            self.write_condition.notify_all()

        result_event_proto = event_to_proto(event)
        return notification_service_pb2.SendEventsResponse(
            event=result_event_proto,
            return_code=str(notification_service_pb2.ReturnStatus.SUCCESS),
            return_msg='')