doorcontrol: Return count of retrieved/created messages in fetch task

This commit is contained in:
Adam Goldsmith 2023-11-20 00:52:34 -05:00
parent f25b67e2f1
commit db238befa6

View File

@ -18,13 +18,23 @@ def getMessages(door: Door):
else: else:
last_ts = datetime(2010, 1, 1) last_ts = datetime(2010, 1, 1)
retrieved_message_count = 0
created_message_count = 0
for events_page in door.controller.get_events(last_ts): for events_page in door.controller.get_events(last_ts):
print(f"Importing {len(events_page)} events for {door.name}") print(f"Importing {len(events_page)} events for {door.name}")
HIDEvent.objects.bulk_create( created_messages = HIDEvent.objects.bulk_create(
(HIDEvent.from_xml_attributes(door, event.attrib) for event in events_page), (HIDEvent.from_xml_attributes(door, event.attrib) for event in events_page),
ignore_conflicts=True, ignore_conflicts=True,
) )
retrieved_message_count += len(events_page)
created_message_count += len(created_messages)
return {
"retrieved": retrieved_message_count,
"created": created_message_count,
}
def q_getMessagesAllDoors(): def q_getMessagesAllDoors():
# TODO: this should probably use async_iter # TODO: this should probably use async_iter