def __get_tasks_by_state_key_expression()

in source/client/python/api-v0.1/api/state_table_dynamodb.py [0:0]


    def __get_tasks_by_state_key_expression(self, session_id, key_expression):
        """
        Returns:
            Returns a list of tasks in the specified status from the associated session

        Throws:
            StateTableException on throttling
            Exception for all other errors

        """

        combined_response = None
        try:

            query_kwargs = {
                'IndexName': "gsi_session_index",
                'KeyConditionExpression': key_expression
            }

            last_evaluated_key = None
            done = False
            while not done:

                if last_evaluated_key:
                    query_kwargs['ExclusiveStartKey'] = last_evaluated_key

                response = self.state_table.query(**query_kwargs)

                last_evaluated_key = response.get('LastEvaluatedKey', None)

                done = last_evaluated_key is None

                if not combined_response:
                    combined_response = response
                else:
                    combined_response['Items'] += response['Items']

            return combined_response

        except ClientError as e:
            if e.response['Error']['Code'] in ["ThrottlingException", "ProvisionedThroughputExceededException"]:
                msg = f"Could not read tasks for session status [{session_id}] by key expression from Status Table. Exception: {e}"
                logging.warning(msg)
                raise StateTableException(e, msg, caused_by_throttling=True)

            else:
                msg = f"Could not read tasks for session status [{session_id}] by key expression from Status Table. Exception: {e}"
                logging.warning(msg)
                raise Exception(e)

        except Exception as e:
            logging.error("Could not read tasks for session status [{}] by key expression from Status Table. Exception: {}".format(session_id, e))
            raise e