Untitled
unknown
plain_text
2 years ago
2.0 kB
7
Indexable
def update_polling_counts_for_batch(client, aggregated_values, timestamp): table_name = os.getenv(MEGLO_DEVICE_HEALTH_TABLE_NAME, default=None) polling_type = os.getenv(LAMBDA_TYPE, default=None) current_month_attributes = __get_current_month_ddb_attributes() polling_attribute = current_month_attributes[POLLING_COUNT] err_attribute = current_month_attributes[POLLING_ERROR] conn_err_attribute = current_month_attributes[CONNECTION_ERROR] # these are all Counter type aggregated_polling_count = aggregated_values[POLLING_COUNT] aggregated_polling_errors = aggregated_values[POLLING_ERROR] aggregated_connection_errors = aggregated_values[CONNECTION_ERROR] data_centers = aggregated_polling_count.keys() # aggregated_polling_count contains each data center processed put_requests = [] for data_center in data_centers: polling_count = aggregated_polling_count[data_center] polling_errors = aggregated_polling_errors[data_center] connection_errors = aggregated_connection_errors[data_center] put_request = { "PutRequest": { "Item": { DATA_CENTER: {"S": data_center.lower()}, POLLING_TYPE: {"S": polling_type.lower()}, polling_attribute: {"N": str(polling_count)}, err_attribute: {"N": str(polling_errors)}, conn_err_attribute: {"N": str(connection_errors)}, POLLING_COUNT_CURRENT_MIN: {"N": str(polling_count)}, ERROR_COUNT_CURRENT_MIN: {"N": str(polling_errors)}, LAST_PROCESSED: {"N": str(timestamp)} } } } put_requests.append(put_request) request_items = { table_name: put_requests } # Execute batch write request response = client.batch_write_item(RequestItems=request_items) return response
Editor is loading...