Merge pull request #80 from ramielrowe/delete_on_non_delete_exist
Only set delete field when deleted_at set on notification
This commit is contained in:
commit
c02be678a9
@ -290,8 +290,6 @@ def _process_exists(raw, body):
|
|||||||
launched_range = (launched_at, launched_at+1)
|
launched_range = (launched_at, launched_at+1)
|
||||||
usage = STACKDB.get_instance_usage(instance=instance_id,
|
usage = STACKDB.get_instance_usage(instance=instance_id,
|
||||||
launched_at__range=launched_range)
|
launched_at__range=launched_range)
|
||||||
delete = STACKDB.get_instance_delete(instance=instance_id,
|
|
||||||
launched_at__range=launched_range)
|
|
||||||
values = {}
|
values = {}
|
||||||
values['message_id'] = body['message_id']
|
values['message_id'] = body['message_id']
|
||||||
values['instance'] = instance_id
|
values['instance'] = instance_id
|
||||||
@ -303,14 +301,19 @@ def _process_exists(raw, body):
|
|||||||
values['instance_type_id'] = payload['instance_type_id']
|
values['instance_type_id'] = payload['instance_type_id']
|
||||||
if usage:
|
if usage:
|
||||||
values['usage'] = usage
|
values['usage'] = usage
|
||||||
if delete:
|
|
||||||
values['delete'] = delete
|
|
||||||
values['raw'] = raw
|
values['raw'] = raw
|
||||||
|
|
||||||
deleted_at = payload.get('deleted_at')
|
deleted_at = payload.get('deleted_at')
|
||||||
if deleted_at and deleted_at != '':
|
if deleted_at and deleted_at != '':
|
||||||
|
# We only want to pre-populate the 'delete' if we know this is in fact
|
||||||
|
# an exist event for a deleted instance. Otherwise, there is a
|
||||||
|
# chance we may populate it for a previous period's exist.
|
||||||
|
delete = STACKDB.get_instance_delete(instance=instance_id,
|
||||||
|
launched_at__range=launched_range)
|
||||||
deleted_at = utils.str_time_to_unix(deleted_at)
|
deleted_at = utils.str_time_to_unix(deleted_at)
|
||||||
values['deleted_at'] = deleted_at
|
values['deleted_at'] = deleted_at
|
||||||
|
if delete:
|
||||||
|
values['delete'] = delete
|
||||||
|
|
||||||
exists = STACKDB.create_instance_exists(**values)
|
exists = STACKDB.create_instance_exists(**values)
|
||||||
STACKDB.save(exists)
|
STACKDB.save(exists)
|
||||||
|
@ -629,9 +629,6 @@ class StacktackUsageParsingTestCase(unittest.TestCase):
|
|||||||
views.STACKDB.get_instance_usage(instance=INSTANCE_ID_1,
|
views.STACKDB.get_instance_usage(instance=INSTANCE_ID_1,
|
||||||
launched_at__range=launched_range)\
|
launched_at__range=launched_range)\
|
||||||
.AndReturn(usage)
|
.AndReturn(usage)
|
||||||
views.STACKDB.get_instance_delete(instance=INSTANCE_ID_1,
|
|
||||||
launched_at__range=launched_range)\
|
|
||||||
.AndReturn(None)
|
|
||||||
exists_values = {
|
exists_values = {
|
||||||
'message_id': MESSAGE_ID_1,
|
'message_id': MESSAGE_ID_1,
|
||||||
'instance': INSTANCE_ID_1,
|
'instance': INSTANCE_ID_1,
|
||||||
|
Loading…
Reference in New Issue
Block a user