コード例 #1
0
 async def checkpoint_async(self):
     """
     Generates a checkpoint for the partition using the curren offset and sequenceNumber for
     and persists to the checkpoint manager.
     """
     captured_checkpoint = Checkpoint(self.partition_id, self.offset, self.sequence_number)
     await self.persist_checkpoint_async(captured_checkpoint)
コード例 #2
0
    async def checkpoint_async_event_data(self, event_data, event_processor_context=None):
        """
        Stores the offset and sequenceNumber from the provided received EventData instance,
        then writes those values to the checkpoint store via the checkpoint manager.
        Optionally stores the state of the Event Processor along the checkpoint.

        :param event_data: A received EventData with valid offset and sequenceNumber.
        :type event_data: ~azure.eventhub.common.EventData
        :param event_processor_context An optional custom state value for the Event Processor.
         This data must be in a JSON serializable format.
        :type event_processor_context: str or dict
        :raises: ValueError if suplied event_data is None.
        :raises: ValueError if the sequenceNumber is less than the last checkpointed value.
        """
        if not event_data:
            raise ValueError("event_data")
        if event_data.sequence_number > self.sequence_number:
            #We have never seen this sequence number yet
            raise ValueError("Argument Out Of Range event_data x-opt-sequence-number")

        await self.persist_checkpoint_async(Checkpoint(self.partition_id,
                                                       event_data.offset,
                                                       event_data.sequence_number),
                                            event_processor_context)
        self.event_processor_context = event_processor_context
 async def create_checkpoint_if_not_exists_async(self, partition_id):
     """
     Create the given partition checkpoint if it doesn't exist.Do nothing if it does exist.
     The offset/sequenceNumber for a freshly-created checkpoint should be set to StartOfStream/0.
     :returns: The checkpoint for the given partition, whether newly created or already existing.
     """
     checkpoint = await self.get_checkpoint_async(partition_id)
     if not checkpoint:
         await self.create_lease_if_not_exists_async(partition_id)
         checkpoint = Checkpoint(partition_id)
     return checkpoint
コード例 #4
0
    async def checkpoint_async(self, event_processor_context=None):
        """
        Generates a checkpoint for the partition using the curren offset and sequenceNumber for
        and persists to the checkpoint manager.

        :param event_processor_context An optional custom state value for the Event Processor.
         This data must be in a JSON serializable format.
        :type event_processor_context: str or dict
        """
        captured_checkpoint = Checkpoint(self.partition_id, self.offset, self.sequence_number)
        await self.persist_checkpoint_async(captured_checkpoint, event_processor_context)
        self.event_processor_context = event_processor_context
 async def get_checkpoint_async(self, partition_id):
     """
     Get the checkpoint data associated with the given partition.
     Could return null if no checkpoint has been created for that partition.
     :returns: Given partition checkpoint info, or `None` if none has been previously stored.
     """
     lease = await self.get_lease_async(partition_id)
     checkpoint = None
     if lease:
         if lease.offset:
             checkpoint = Checkpoint(partition_id, lease.offset,
                                     lease.sequence_number)
     return checkpoint
コード例 #6
0
    async def create_checkpoint_if_not_exists_async(self, partition_id):
        """
        Create the given partition checkpoint if it doesn't exist.Do nothing if it does exist.
        The offset/sequenceNumber for a freshly-created checkpoint should be set to StartOfStream/0.

        :param partition_id: The partition ID.
        :type partition_id: str
        :return: The checkpoint for the given partition, whether newly created or already existing.
        :rtype: ~azure.eventprocessorhost.checkpoint.Checkpoint
        """
        checkpoint = await self.get_checkpoint_async(partition_id)
        if not checkpoint:
            await self.create_lease_if_not_exists_async(partition_id)
            checkpoint = Checkpoint(partition_id)
        return checkpoint
コード例 #7
0
    async def get_checkpoint_async(self, partition_id):
        """
        Get the checkpoint data associated with the given partition.
        Could return null if no checkpoint has been created for that partition.

        :param partition_id: The partition ID.
        :type partition_id: str
        :return: Given partition checkpoint info, or `None` if none has been previously stored.
        :rtype: ~azure.eventprocessorhost.checkpoint.Checkpoint
        """
        lease = await self.get_lease_async(partition_id)
        checkpoint = None
        if lease:
            if lease.offset:
                checkpoint = Checkpoint(partition_id, lease.offset,
                                        lease.sequence_number)
        return checkpoint
コード例 #8
0
    async def checkpoint_async_event_data(self, event_data):
        """
        Stores the offset and sequenceNumber from the provided received EventData instance,
        then writes those values to the checkpoint store via the checkpoint manager.

        :param event_data: A received EventData with valid offset and sequenceNumber.
        :type event_data: ~azure.eventhub.common.EventData
        :raises: ValueError if suplied event_data is None.
        :raises: ValueError if the sequenceNumber is less than the last checkpointed value.
        """
        if not event_data:
            raise ValueError("event_data")
        if event_data.sequence_number > self.sequence_number:
            #We have never seen this sequence number yet
            raise ValueError("Argument Out Of Range event_data x-opt-sequence-number")

        await self.persist_checkpoint_async(Checkpoint(self.partition_id,
                                                       event_data.offset,
                                                       event_data.sequence_number))