def get_messages(self, **kwargs): person_name = kwargs.get('PersonName', '') self.sqs_msgs = [] """get all available messages off the queue""" print "Checking message queue" messages = self.queue.receive_messages(MessageAttributeNames=[ 'NoMoreOccurrences', 'ExpirationDateTimeInUtc', 'PersonName', 'Voice', 'UUID' ], WaitTimeSeconds=20, MaxNumberOfMessages=10) if len(messages) > 0: for m in messages: qm = QueuedMessage(QueuedMessage=m) if not qm.person_name == person_name: continue if qm.person_name not in self.messages: logging.info("First message for " + qm.person_name) self.messages[qm.person_name] = [] logging.info('Adding message:\n') logging.info(qm.body) self.messages[qm.person_name].append(qm) logging.info('Total messages so far: ' + str(len(self.messages[qm.person_name]))) self.sqs_msgs.append(m) scheduler = Scheduler() scheduler.update_queue_status(qm.uuid_key, person_name, False)
def fail_speech(self, **kwargs): logging.info('Speech failed: ' + kwargs.get('Reason', 'Unknown Reason')) dont_delete = kwargs.get('DontDelete', False) if (dont_delete): logging.info('We are NOT deleting the original SQS messages') return for m in self.sqs_msgs: scheduler = Scheduler() qm = QueuedMessage(QueuedMessage=m) logging.info("Setting messages InQueue to False") scheduler.update_queue_status(qm.uuid_key, qm.person_name, False) self.delete_sqs_msgs()
def succeed_speech(self, **kwargs): logging.info('Speech succeeded.') dont_delete = kwargs.get('DontDelete', False) if (dont_delete): logging.info('We are NOT deleting the original SQS messages') return scheduler = Scheduler() for m in self.sqs_msgs: logging.info('Deleting message from queue') qm = QueuedMessage(QueuedMessage=m) scheduler.update_last_occurrence(qm.uuid_key, qm.person_name) scheduler.update_queue_status(qm.uuid_key, qm.person_name, False) if qm.no_more_occurrences: scheduler.set_expired(qm.uuid_key, qm.person_name) self.delete_sqs_msgs()
def get_messages(self, **kwargs): person_name = kwargs.get('PersonName', '') message_type = kwargs.get('MessageType', 'Message') wait_time_seconds = kwargs.get('WaitTimeSeconds', 0) max_number_of_messages = kwargs.get('MaxNumberOfMessages', 10) self.sqs_msgs = [] self.log.debug( "Checking messages in the queue, person={}, type={}".format( person_name, message_type)) messages = {} queue = None if message_type == "Message": queue = self.queue else: queue = self.bot_queue messages = queue.receive_messages( MessageAttributeNames=[ 'NoMoreOccurrences', 'ExpirationDateTimeInUtc', 'PersonName', 'Voice', 'BotNames', 'RequiredBots', 'IceBreaker', 'UUID' ], WaitTimeSeconds=wait_time_seconds, MaxNumberOfMessages=max_number_of_messages) self.log.debug(len(messages)) if len(messages) > 0: self.log.debug('Received {}:'.format(len(messages))) msgs = [] for m in messages: qm = QueuedMessage(QueuedMessage=m) if person_name and not qm.person_name == person_name: self.log.debug( 'Skipping message for {}, looking for {}'.format( qm.person_name, person_name)) continue if qm.person_name not in self.messages: self.log.debug("First message for " + qm.person_name) self.messages[qm.person_name] = [] self.messages[qm.person_name].append(qm) self.sqs_msgs.append(m) msgs.append(qm) scheduler = Scheduler() scheduler.update_queue_status(qm.uuid_key, qm.person_name, False) return msgs