Skip to content

Commit 57b8d06

Browse files
author
Christopher Rabotin
committed
Added autocommit to Meta class. Failing tests are more explicit.
1 parent ae739fb commit 57b8d06

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

influxdb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
]
1212

1313

14-
__version__ = '0.1.14'
14+
__version__ = '0.1.13'

influxdb/helper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class Meta:
2525
# Defines all the fields in this time series.
2626
bulk_size = 5
2727
# Defines the number of data points to store prior to writing on the wire.
28+
autocommit = True
29+
# Sets autocommit: must be set to True for bulk_size to have any affect.
2830
2931
# The following will create *five* (immutable) data points.
3032
# Since bulk_size is set to 5, upon the fifth construction call, *all* data
@@ -35,6 +37,7 @@ class Meta:
3537
MySeriesHelper(server_name='us.east-1', time=156)
3638
MySeriesHelper(server_name='us.east-1', time=155)
3739
40+
# If autocommit unset (or set to False), one must call commit to write datapoints.
3841
# To manually submit data points which are not yet written, call commit:
3942
MySeriesHelper.commit()
4043
@@ -61,6 +64,7 @@ def __new__(cls, *args, **kwargs):
6164
except AttributeError:
6265
raise AttributeError('Missing {} in {} Meta class.'.format(attr, cls.__name__))
6366

67+
cls._autocommit = getattr(_meta, 'autocommit', False)
6468
cls._bulk_size = getattr(_meta, 'bulk_size', 1)
6569

6670
cls._datapoints = defaultdict(list)
@@ -81,7 +85,7 @@ def __init__(self, **kw):
8185

8286
cls._datapoints[cls._series_name.format(**kw)].append(cls._type(**kw))
8387

84-
if len(cls._datapoints) >= cls._bulk_size:
88+
if cls._autocommit and len(cls._datapoints) >= cls._bulk_size:
8589
cls.commit()
8690

8791
@classmethod

tests/influxdb/helper_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Meta:
1818
series_name = 'events.stats.{server_name}'
1919
fields = ['time', 'server_name']
2020
bulk_size = 5
21+
autocommit = False
2122

2223
TestSeriesHelper.MySeriesHelper = MySeriesHelper
2324

@@ -35,7 +36,8 @@ def testSingleSeriesName(self):
3536
[156, 'us.east-1']],
3637
'name': 'events.stats.us.east-1',
3738
'columns': ['time', 'server_name']}]
38-
self.assertListEqual(TestSeriesHelper.MySeriesHelper._json_body_(), expectation, 'Invalid JSON body of time series returned from _json_body_ for one series name.')
39+
rcvd = TestSeriesHelper.MySeriesHelper._json_body_()
40+
self.assertListEqual(rcvd, expectation, 'Invalid JSON body of time series returned from _json_body_ for one series name: {}.'.format(rcvd))
3941
TestSeriesHelper.MySeriesHelper._reset_()
4042
self.assertEqual(TestSeriesHelper.MySeriesHelper._json_body_(), [], 'Resetting helper did not empty datapoints.')
4143

@@ -59,6 +61,7 @@ def testSeveralSeriesNames(self):
5961
{'points': [[159, 'us.east-1']],
6062
'name': 'events.stats.us.east-1',
6163
'columns': ['time', 'server_name']}]
62-
self.assertListEqual(TestSeriesHelper.MySeriesHelper._json_body_(), expectation, 'Invalid JSON body of time series returned from _json_body_ for several series names.')
64+
rcvd = TestSeriesHelper.MySeriesHelper._json_body_()
65+
self.assertListEqual(rcvd, expectation, 'Invalid JSON body of time series returned from _json_body_ for several series names: {}.'.format(rcvd))
6366
TestSeriesHelper.MySeriesHelper._reset_()
6467
self.assertEqual(TestSeriesHelper.MySeriesHelper._json_body_(), [], 'Resetting helper did not empty datapoints.')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy