Пример #1
0
def test_retry_logic():
    VISIBILITY_TIMEOUT = 2
    MAX_RECEIVE_COUNT = 2
    queue_name = id_generator.generate_job_item_id()
    dead_letter_queue_name = queue_name + "_dead"

    dead_queue = sqs.create_queue(dead_letter_queue_name, 43200)

    dead_arn = dead_queue.attributes['QueueArn']
    redrive_policy = {
        "maxReceiveCount": MAX_RECEIVE_COUNT,
        "deadLetterTargetArn": dead_arn
    }
    queue = sqs.create_queue(queue_name, VISIBILITY_TIMEOUT, redrive_policy)

    # Create Message
    expected_message_id = sqs.send_message(
        queue, 'boto3',
        {'Author': {
            'StringValue': 'Daniel',
            'DataType': 'String'
        }})

    # 1st message request succeeds
    message = sqs.get_next_message(queue)
    assert message['MessageId'] == expected_message_id

    # Visibilty Timeout not exceeded
    message = sqs.get_next_message(queue)
    assert message is None

    # Visibilty Timeout exceeded
    time.sleep(VISIBILITY_TIMEOUT)

    # 2nd message request succeeds
    message = sqs.get_next_message(queue)
    assert message['MessageId'] == expected_message_id

    # Visibilty Timeout exceeded
    time.sleep(VISIBILITY_TIMEOUT)

    # 3rd message request fails - MAX_RECEIVE_COUNT exceeded
    message = sqs.get_next_message(queue)
    assert message is None

    # 3rd message in Dead Letter Queue
    message = sqs.get_next_message(dead_queue)
    assert message['MessageId'] == expected_message_id

    # Cleanup
    time.sleep(VISIBILITY_TIMEOUT)
    sqs.delete_queue(dead_queue)
    sqs.delete_queue(queue)
Пример #2
0
def test_retry_logic():
	VISIBILITY_TIMEOUT = 2
	MAX_RECEIVE_COUNT = 2
	queue_name = id_generator.generate_job_item_id()
	dead_letter_queue_name = queue_name + "_dead"

	dead_queue = sqs.create_queue(dead_letter_queue_name, 43200)
	
	dead_arn = dead_queue.attributes['QueueArn']
	redrive_policy = {"maxReceiveCount":MAX_RECEIVE_COUNT, "deadLetterTargetArn":dead_arn}
	queue = sqs.create_queue(queue_name, VISIBILITY_TIMEOUT, redrive_policy)

	# Create Message
	expected_message_id = sqs.send_message(queue, 'boto3', {
    	'Author': {
        	'StringValue': 'Daniel',
        	'DataType': 'String'
    	}
	})

	# 1st message request succeeds
	message = sqs.get_next_message(queue)
	assert message['MessageId'] == expected_message_id

	# Visibilty Timeout not exceeded
	message = sqs.get_next_message(queue)
	assert message is None

	# Visibilty Timeout exceeded
	time.sleep(VISIBILITY_TIMEOUT)

	# 2nd message request succeeds
	message = sqs.get_next_message(queue)
	assert message['MessageId'] == expected_message_id

	# Visibilty Timeout exceeded
	time.sleep(VISIBILITY_TIMEOUT)

	# 3rd message request fails - MAX_RECEIVE_COUNT exceeded
	message = sqs.get_next_message(queue)
	assert message is None

	# 3rd message in Dead Letter Queue
	message = sqs.get_next_message(dead_queue)
	assert message['MessageId'] == expected_message_id

	# Cleanup
	time.sleep(VISIBILITY_TIMEOUT)
	sqs.delete_queue(dead_queue)
	sqs.delete_queue(queue)
Пример #3
0
def test_get_message_attributes():
    queue_name = id_generator.generate_job_item_id()
    queue = get_test_queue(queue_name)
    expected_message_id = sqs.send_message(
        queue, 'boto3',
        {'Author': {
            'StringValue': 'Daniel',
            'DataType': 'String'
        }})
    message = sqs.get_next_message(queue)
    assert message['Attributes'] is not None
    print message['Attributes']['ApproximateReceiveCount']
    print message['Attributes']['ApproximateFirstReceiveTimestamp']
Пример #4
0
def test_send_and_get_message():
    queue_name = id_generator.generate_job_item_id()
    queue = get_test_queue(queue_name)
    message_id = sqs.send_message(
        queue, 'boto3',
        {'Author': {
            'StringValue': 'Daniel',
            'DataType': 'String'
        }})
    time.sleep(5)  # Accounts for 5 second delivery delay
    message = sqs.get_next_message(queue)
    assert message_id == message['MessageId']
    sqs.delete_queue(queue)
Пример #5
0
def test_get_message_attributes():
	queue_name = id_generator.generate_job_item_id()
	queue = get_test_queue(queue_name)
	expected_message_id = sqs.send_message(queue, 'boto3', {
    	'Author': {
        	'StringValue': 'Daniel',
        	'DataType': 'String'
    	}
	})
	message = sqs.get_next_message(queue)
	assert message['Attributes'] is not None
	print message['Attributes']['ApproximateReceiveCount']
	print message['Attributes']['ApproximateFirstReceiveTimestamp']
Пример #6
0
def test_send_and_get_message():
	queue_name = id_generator.generate_job_item_id()
	queue = get_test_queue(queue_name)
	message_id = sqs.send_message(queue, 'boto3', {
    	'Author': {
        	'StringValue': 'Daniel',
        	'DataType': 'String'
    	}
	})
	time.sleep(5)  # Accounts for 5 second delivery delay
	message = sqs.get_next_message(queue)
	assert message_id == message['MessageId']
	sqs.delete_queue(queue)
Пример #7
0
def process_next_job_item():
	tasks_log.info("Getting next job_item from queue")
	queue = sqs.get_queue(client_constants.SQS_JOB_ITEMS_QUEUE)
	msg = sqs.get_next_message(queue)
	if msg is None: 
		tasks_log.info("No job items found in Queue")
		return
	job_item_key = msg['MessageAttributes']['job_item_key']['StringValue']
	tasks_log.info("Found new job_item " + job_item_key)
	job_item = job_item_manager.get_job_item_doc(job_item_key)
	job_item['attempts'] += 1
	status = job_item_manager.process_job_item(job_item)
	if status == "COMPLETE":
		items_log.info("Deleting completed job_item from queue")
		sqs.delete_message(queue, msg)
	else:
		# We are going to let SQS handle retries
		items_log.info("Leaving job_item in queue")
		
Пример #8
0
def test_update_msg_visibility_timeout():
    job_item_key = id_generator.generate_job_item_id()
    queue_name = id_generator.generate_job_item_id()
    queue = get_test_queue(queue_name)

    attribs = {}
    attribs['VisibilityTimeout'] = str(120)
    sqs.set_queue_attributes(queue, attribs)

    message_id = sqs.send_message(
        queue, 'boto3',
        {"job_item_key": {
            "StringValue": job_item_key,
            "DataType": "String"
        }})
    # 1st Try
    message = sqs.get_message_by_key(queue.url, job_item_key)
    msg_receipt = message['ReceiptHandle']
    assert message is not None

    # 2nd - Visibilty Timeout not exceeded
    message = sqs.get_message_by_key(queue.url, job_item_key)
    assert message is None

    new_timeout = 10
    response = sqs.update_msg_visibility_timeout(queue.url, msg_receipt,
                                                 new_timeout)

    # 3rd - Visibilty Timeout not exceeded
    message = sqs.get_message_by_key(queue.url, job_item_key)
    assert message is None

    # Visibilty Timeout exceeded
    time.sleep(new_timeout)

    # 4th message request succeeds
    message = sqs.get_next_message(queue)
    assert message['MessageId'] == message_id

    sqs.delete_queue(queue)
Пример #9
0
def test_update_msg_visibility_timeout():
	job_item_key = id_generator.generate_job_item_id()
	queue_name = id_generator.generate_job_item_id()
	queue = get_test_queue(queue_name)

	attribs = {}
	attribs['VisibilityTimeout'] = str(120)
	sqs.set_queue_attributes(queue, attribs)

	message_id = sqs.send_message(queue, 'boto3', {
		"job_item_key" : { 
			"StringValue" : job_item_key, 
			"DataType" : "String"
		}
	})
	# 1st Try
	message = sqs.get_message_by_key(queue.url, job_item_key)
	msg_receipt = message['ReceiptHandle']
	assert message is not None

	# 2nd - Visibilty Timeout not exceeded
	message = sqs.get_message_by_key(queue.url, job_item_key)
	assert message is None

	new_timeout = 10
	response = sqs.update_msg_visibility_timeout(queue.url, 
		msg_receipt, new_timeout)

	# 3rd - Visibilty Timeout not exceeded
	message = sqs.get_message_by_key(queue.url, job_item_key)
	assert message is None

	# Visibilty Timeout exceeded
	time.sleep(new_timeout)

	# 4th message request succeeds
	message = sqs.get_next_message(queue)
	assert message['MessageId'] == message_id

	sqs.delete_queue(queue)