Skip to content

Commit

Permalink
Wrap create bucket in try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
gcrevell committed Feb 13, 2021
1 parent a78da12 commit b4efd15
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions varken/influxdb2manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ def __init__(self, server):

bucket_api = self.influx.buckets_api()

bucket = bucket_api.find_bucket_by_name(self.server.bucket)
try:
bucket = bucket_api.find_bucket_by_name(self.server.bucket)

if bucket is None:
self.logger.info('Creating bucket %s', self.server.bucket)
if bucket is None:
self.logger.info('Creating bucket %s', self.server.bucket)

org_api = influxdb_client.service.organizations_service.OrganizationsService(self.influx.api_client)
orgs = org_api.get_orgs()
for org in orgs.orgs:
if org.name == self.server.org:
my_org = org
org_api = influxdb_client.service.organizations_service.OrganizationsService(self.influx.api_client)
orgs = org_api.get_orgs()
for org in orgs.orgs:
if org.name == self.server.org:
my_org = org

self.influx.buckets_api().create_bucket(bucket_name=self.server.bucket, org_id=my_org.id)
self.influx.buckets_api().create_bucket(bucket_name=self.server.bucket, org_id=my_org.id)
except Exception as e:
self.logger.error('Failed creating new InfluxDB bucket! Error: %s', e)

def write_points(self, data):
d = data
Expand Down

0 comments on commit b4efd15

Please sign in to comment.