def transmit(self, payload, **kwargs):
        """
        Transmit content metadata items to the integrated channel.
        """
        items_to_create, items_to_update, items_to_delete, transmission_map = self._partition_items(
            payload)
        self._prepare_items_for_delete(items_to_delete)
        prepared_items = {}
        prepared_items.update(items_to_create)
        prepared_items.update(items_to_update)
        prepared_items.update(items_to_delete)

        skip_metadata_transmission = False

        for chunk in chunks(
                prepared_items,
                self.enterprise_configuration.transmission_chunk_size):
            chunked_items = list(chunk.values())
            if skip_metadata_transmission:
                # Remove the failed items from the create/update/delete dictionaries,
                # so ContentMetadataItemTransmission objects are not synchronized for
                # these items below.
                self._remove_failed_items(chunked_items, items_to_create,
                                          items_to_update, items_to_delete)
            else:
                try:
                    self.client.update_content_metadata(
                        self._serialize_items(chunked_items))
                except ClientError as exc:
                    LOGGER.error(
                        'Failed to update [%s] content metadata items for integrated channel [%s] [%s]',
                        len(chunked_items),
                        self.enterprise_configuration.enterprise_customer.name,
                        self.enterprise_configuration.channel_code(),
                    )
                    LOGGER.exception(exc)

                    # Remove the failed items from the create/update/delete dictionaries,
                    # so ContentMetadataItemTransmission objects are not synchronized for
                    # these items below.
                    self._remove_failed_items(chunked_items, items_to_create,
                                              items_to_update, items_to_delete)

                    # SAP servers throttle incoming traffic, If a request fails than the subsequent would fail too,
                    # So, no need to keep trying and failing. We should stop here and retry later.
                    skip_metadata_transmission = True

        self._create_transmissions(items_to_create)
        self._update_transmissions(items_to_update, transmission_map)
        self._delete_transmissions(items_to_delete.keys())
Exemple #2
0
    def transmit(self, payload, **kwargs):
        """
        Transmit content metadata items to the integrated channel.
        """
        items_to_create, items_to_update, items_to_delete, transmission_map = self._partition_items(
            payload)
        self._prepare_items_for_delete(items_to_delete)
        prepared_items = {}
        prepared_items.update(items_to_create)
        prepared_items.update(items_to_update)
        prepared_items.update(items_to_delete)

        chunk_items = chunks(
            prepared_items,
            self.enterprise_configuration.transmission_chunk_size)
        transmission_limit = settings.INTEGRATED_CHANNELS_API_CHUNK_TRANSMISSION_LIMIT.get(
            self.enterprise_configuration.channel_code())
        for chunk in islice(chunk_items, transmission_limit):
            chunked_items = list(chunk.values())
            try:
                self.client.update_content_metadata(
                    self._serialize_items(chunked_items))
            except ClientError as exc:
                LOGGER.error(
                    'Failed to update [%s] content metadata items for integrated channel [%s] [%s]',
                    len(chunked_items),
                    self.enterprise_configuration.enterprise_customer.name,
                    self.enterprise_configuration.channel_code(),
                )
                LOGGER.exception(exc)

                # Remove the failed items from the create/update/delete dictionaries,
                # so ContentMetadataItemTransmission objects are not synchronized for
                # these items below.
                self._remove_failed_items(chunked_items, items_to_create,
                                          items_to_update, items_to_delete)

        # If API transmission limit is set then mark the rest of the items as not transmitted.
        # Since, chunk_items is a generator and we have already iterated through the items that need to
        # be transmitted. Rest of the items are the ones that need to marked as not transmitted.
        for chunk in chunk_items:
            chunked_items = list(chunk.values())
            self._remove_failed_items(chunked_items, items_to_create,
                                      items_to_update, items_to_delete)

        self._create_transmissions(items_to_create)
        self._update_transmissions(items_to_update, transmission_map)
        self._delete_transmissions(list(items_to_delete.keys()))
 def _transmit_delete(self, channel_metadata_item_map):
     """
     Transmit content metadata deletion to integrated channel.
     """
     for chunk in chunks(channel_metadata_item_map, self.enterprise_configuration.transmission_chunk_size):
         serialized_chunk = self._serialize_items(list(chunk.values()))
         try:
             self.client.delete_content_metadata(serialized_chunk)
         except ClientError as exc:
             LOGGER.error(
                 'Failed to delete [%s] content metadata items for integrated channel [%s] [%s]',
                 len(chunk),
                 self.enterprise_configuration.enterprise_customer.name,
                 self.enterprise_configuration.channel_code(),
             )
             LOGGER.exception(exc)
         else:
             self._delete_transmissions(chunk.keys())
 def _transmit_delete(self, channel_metadata_item_map):
     """
     Transmit content metadata deletion to integrated channel.
     """
     chunk_items = chunks(
         channel_metadata_item_map,
         self.enterprise_configuration.transmission_chunk_size)
     transmission_limit = settings.INTEGRATED_CHANNELS_API_CHUNK_TRANSMISSION_LIMIT.get(
         self.enterprise_configuration.channel_code())
     for chunk in islice(chunk_items, transmission_limit):
         serialized_chunk = self._serialize_items(list(chunk.values()))
         try:
             self.client.delete_content_metadata(serialized_chunk)
         except ClientError as exc:
             LOGGER.error(
                 'Failed to delete [%s] content metadata items for integrated channel [%s] [%s]',
                 len(chunk),
                 self.enterprise_configuration.enterprise_customer.name,
                 self.enterprise_configuration.channel_code(),
             )
             LOGGER.exception(exc)
         else:
             self._delete_transmissions(chunk.keys())
Exemple #5
0
    def transmit(self, payload, **kwargs):
        """
        Transmit content metadata items to the integrated channel.
        """
        items_to_create, items_to_update, items_to_delete, transmission_map = self._partition_items(payload)
        self._prepare_items_for_delete(items_to_delete)
        prepared_items = {}
        prepared_items.update(items_to_create)
        prepared_items.update(items_to_update)
        prepared_items.update(items_to_delete)

        for chunk in chunks(prepared_items, self.enterprise_configuration.transmission_chunk_size):
            chunked_items = list(chunk.values())
            try:
                self.client.update_content_metadata(self._serialize_items(chunked_items))
            except ClientError as exc:
                LOGGER.error(
                    'Failed to update [%s] content metadata items for integrated channel [%s] [%s]',
                    len(chunked_items),
                    self.enterprise_configuration.enterprise_customer.name,
                    self.enterprise_configuration.channel_code,
                )
                LOGGER.error(exc)

                # Remove the failed items from the create/update/delete dictionaries,
                # so ContentMetadataItemTransmission objects are not synchronized for
                # these items below.
                for item in chunked_items:
                    content_metadata_id = item['courseID']
                    items_to_create.pop(content_metadata_id, None)
                    items_to_update.pop(content_metadata_id, None)
                    items_to_delete.pop(content_metadata_id, None)

        self._create_transmissions(items_to_create)
        self._update_transmissions(items_to_update, transmission_map)
        self._delete_transmissions(items_to_delete.keys())