def ack(self, *message_identifiers): if len(message_identifiers) > DELETE_MESSAGE_BATCH_SIZE: for message_identifiers in chunk_list(message_identifiers, DELETE_MESSAGE_BATCH_SIZE): self.ack(*message_identifiers) return if len(message_identifiers) == 1: receipt_handle = message_identifiers[0] message = MockMessage(receipt_handle) result = self._boto_queue.delete_message(message) assert result, 'Failed to accept %s' % receipt_handle elif message_identifiers: messages = [] for num, receipt_handle in enumerate(message_identifiers, start=1): message = MockMessage(receipt_handle, batch_id=num) messages.append(message) result = self._boto_queue.delete_message_batch(messages) assert result, 'Result is %r' % result assert len(result.errors) == 0, 'Errors are %r' % result.errors assert len(result.results) == len(messages), 'Got %r expected roughly %r' % (result.results, message_identifiers) if self.timeouts: self.timeouts.remove(*message_identifiers)
def put(self, *message_bodies): num_messages = len(message_bodies) if num_messages == 1: message = Message() message.set_body(message_bodies[0]) status = self._boto_queue.write(message) assert status elif num_messages > WRITE_MESSAGE_BATCH_SIZE: for message_bodies in chunk_list(message_bodies, WRITE_MESSAGE_BATCH_SIZE): self.put(*message_bodies) elif num_messages: messages = [] for num, message_body in enumerate(message_bodies, start=1): message_body = Message(body=message_body).get_body_encoded() message = (str(num), message_body, 0) messages.append(message) result = self._boto_queue.write_batch(messages) assert result, 'Result is %r' % result assert len(result.errors) == 0, 'Errors are %r' % result.errors assert len(result.results) == len( messages), 'Got %r expected roughly %r' % (result.results, message_bodies)
def ack(self, *message_identifiers): if len(message_identifiers) > DELETE_MESSAGE_BATCH_SIZE: for message_identifiers in chunk_list(message_identifiers, DELETE_MESSAGE_BATCH_SIZE): self.ack(*message_identifiers) return if len(message_identifiers) == 1: receipt_handle = message_identifiers[0] message = MockMessage(receipt_handle) result = self._boto_queue.delete_message(message) assert result, 'Failed to accept %s' % receipt_handle elif message_identifiers: messages = [] for num, receipt_handle in enumerate(message_identifiers, start=1): message = MockMessage(receipt_handle, batch_id=num) messages.append(message) result = self._boto_queue.delete_message_batch(messages) assert result, 'Result is %r' % result assert len(result.errors) == 0, 'Errors are %r' % result.errors assert len(result.results) == len( messages), 'Got %r expected roughly %r' % (result.results, message_identifiers) if self.timeouts: self.timeouts.remove(*message_identifiers)
def redeliver(self, *items): """ Set the visibility timeout of messages so they will be redelivered at that point in time (unless they are updated or deleted before then). The items should be tuples of: (visibility_timeout, message_identifier) A message cannot be redelivered before its existing visibility timeout. Any attempt to do so will be ignored, except for the special case of 0, which will work. This is a limitation of this API, not SQS, to avoid making excessive API calls. """ items = tuple(self._clean_redeliver_items(*items)) num_items = len(items) if num_items > CHANGE_MESSAGE_VISIBILITY_BATCH_SIZE: for fewer_items in chunk_list( items, CHANGE_MESSAGE_VISIBILITY_BATCH_SIZE): num_items = len(fewer_items) if num_items == 1: self._redeliver_one(*fewer_items) elif num_items: self._redeliver_batch(*fewer_items) elif num_items: if num_items == 1: self._redeliver_one(*items) elif num_items: self._redeliver_batch(*items) if self.timeouts: for (num_seconds, receipt_handle) in items: self.timeouts.add(num_seconds, receipt_handle)
def redeliver(self, *items): """ Set the visibility timeout of messages so they will be redelivered at that point in time (unless they are updated or deleted before then). The items should be tuples of: (visibility_timeout, message_identifier) A message cannot be redelivered before its existing visibility timeout. Any attempt to do so will be ignored, except for the special case of 0, which will work. This is a limitation of this API, not SQS, to avoid making excessive API calls. """ items = tuple(self._clean_redeliver_items(*items)) num_items = len(items) if num_items > CHANGE_MESSAGE_VISIBILITY_BATCH_SIZE: for fewer_items in chunk_list(items, CHANGE_MESSAGE_VISIBILITY_BATCH_SIZE): num_items = len(fewer_items) if num_items == 1: self._redeliver_one(*fewer_items) elif num_items: self._redeliver_batch(*fewer_items) elif num_items: if num_items == 1: self._redeliver_one(*items) elif num_items: self._redeliver_batch(*items) if self.timeouts: for (num_seconds, receipt_handle) in items: self.timeouts.add(num_seconds, receipt_handle)
def put(self, *message_bodies): num_messages = len(message_bodies) if num_messages == 1: message = Message() message.set_body(message_bodies[0]) status = self._boto_queue.write(message) assert status elif num_messages > WRITE_MESSAGE_BATCH_SIZE: for message_bodies in chunk_list(message_bodies, WRITE_MESSAGE_BATCH_SIZE): self.put(*message_bodies) elif num_messages: messages = [] for num, message_body in enumerate(message_bodies, start=1): message_body = Message(body=message_body).get_body_encoded() message = (str(num), message_body, 0) messages.append(message) result = self._boto_queue.write_batch(messages) assert result, 'Result is %r' % result assert len(result.errors) == 0, 'Errors are %r' % result.errors assert len(result.results) == len(messages), 'Got %r expected roughly %r' % (result.results, message_bodies)