Created
July 21, 2019 14:38
-
-
Save shantanoo-desai/9615a95117016807669c4c4ce7fc642b to your computer and use it in GitHub Desktop.
upload_data function logic for Batch Uploader InfluxDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def upload_data(batch_data): | |
if connected_to_cloud(): | |
try: | |
if CLOUD_DB.write_points(batch_data, time_precision='ms'): | |
logger.info('Write Successful to Cloud') | |
logger.info('Updating local database with status=1 field') | |
# for each point add `status=1` field | |
for point in batch_data: | |
point['fields']['status'] = 1 | |
if LOCAL_DB.write_points(batch_data, write_precision='ms'): | |
logger.info('Local DB updated') | |
except InfluxDBClientError as e: | |
LOCAL_DB.close() | |
CLOUD_DB.close() | |
raise(e) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment