Ejemplo n.º 1
0
    def events(self) -> Response:
        """
        Reads off of the Redis async events stream, using the user's JWT token and
        optional query params for last event received.
        ---
        get:
          description: >-
            Reads off of the Redis events stream, using the user's JWT token and
            optional query params for last event received.
          parameters:
          - in: query
            name: last_id
            description: Last ID received by the client
            schema:
                type: string
          responses:
            200:
              description: Async event results
              content:
                application/json:
                  schema:
                    type: object
                    properties:
                        result:
                            type: array
                            items:
                              type: object
                              properties:
                                id:
                                  type: string
                                channel_id:
                                  type: string
                                job_id:
                                  type: string
                                user_id:
                                  type: integer
                                status:
                                  type: string
                                errors:
                                  type: array
                                  items:
                                    type: object
                                result_url:
                                  type: string
            401:
              $ref: '#/components/responses/401'
            500:
              $ref: '#/components/responses/500'
        """
        try:
            async_channel_id = async_query_manager.parse_jwt_from_request(
                request)["channel"]
            last_event_id = request.args.get("last_id")
            events = async_query_manager.read_events(async_channel_id,
                                                     last_event_id)

        except AsyncQueryTokenException:
            return self.response_401()

        return self.response(200, result=events)
Ejemplo n.º 2
0
 def validate_async_request(self, request: Request) -> None:
     jwt_data = async_query_manager.parse_jwt_from_request(request)
     self._async_channel_id = jwt_data["channel"]