Skip to content

Commit 8df3ba9

Browse files
committed
Add parameters to AsyncBufferedConsumer
The `AsyncBufferedConsumer` constructor now supports more arguments. Those are the same as for the `BufferConsumer` coming from the official Mixpanel package, which is used under the hood. I removed the `*args` and `**kwargs` parameters so that only supported arguments are accepted. This should avoid surprises for users. This breaking change is mentioned in the changelog.
1 parent b2f2007 commit 8df3ba9

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
* New parameters for the `AsyncBufferedConsumer` constructor: `import_url`,
13+
`request_timeout`, `groups_url`, `api_host`, `retry_limit`, `retry_backoff_factor`,
14+
`verify_cert`.
15+
16+
### Changed
17+
18+
* Extra arguments (`*args`, `**kwargs`) are no longer accepted in the
19+
`AsyncBufferedConsumer` constructor.
20+
1021
## [0.2.0] - 2019-07-11
1122

1223
### Added

README.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ For most users, the default configuration should work perfectly. For more specif
3434

3535

3636
* `flush_after (datetime.timedelta)` - *defaults to 10 seconds* - the time period after which the AsyncBufferedConsumer will flush the events upon receiving a new event (no matter what the event queue size is)
37-
3837
* `flush_first (bool)` - *defaults to True* - whether the consumer should always flush the first event.
39-
4038
* `max_size (int)` - *defaults to 20* - how big a given event queue can get before it is flushed by the consumer
41-
4239
* `events_url (str)` - *defaults to standard Mixpanel API URL* - the Mixpanel API URL that track events will be sent to
43-
4440
* `people_url (str)` - *defaults to standard Mixpanel API URL* - the Mixpanel API URL that people events will be sent to
41+
* `import_url (str)` - *defaults to standard Mixpanel API URL* - the Mixpanel API URL that import events will be sent to
42+
* `request_timeout (int)` - *defaults to `None` (no timeout)* - Connection timeout in seconds.
43+
* `groups_url (str)` - *defaults to standard Mixpanel API URL* - the Mixpanel API URL that groups events will be sent to
44+
* `api_host (str)` - *defaults to api.mixpanel.com* - Mixpanel API domain for all requests unless overridden by above URLs
45+
* `retry_limit (int)` - *defaults to 4* - Number of times to retry each request in case of an error, 0 to fail after first attempt.
46+
* `retry_backoff_factor` - *defaults to 0.25* - Factor which controls sleep duration between retries: `sleep_seconds = backoff_factor * (2 ^ (retry_count - 1))`
47+
* `verify_cert` - *defaults to `True`*- Whether to verify the server certificate. `True` is recommended.
4548

4649
### Usage
4750

mixpanel_async/async_buffered_consumer.py

+35-5
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,21 @@ class AsyncBufferedConsumer(SynchronousBufferedConsumer):
5353
ALL = "ALL"
5454
ENDPOINT = "ENDPOINT"
5555

56-
def __init__(self, flush_after=timedelta(0, 10), flush_first=True, max_size=20,
57-
events_url=None, people_url=None, *args, **kwargs):
56+
def __init__(
57+
self,
58+
flush_after=timedelta(0, 10),
59+
flush_first=True,
60+
max_size=20,
61+
events_url=None,
62+
people_url=None,
63+
import_url=None,
64+
request_timeout=None,
65+
groups_url=None,
66+
api_host="api.mixpanel.com",
67+
retry_limit=4,
68+
retry_backoff_factor=0.25,
69+
verify_cert=True,
70+
):
5871
'''
5972
Create a new instance of a AsyncBufferedConsumer class.
6073
@@ -65,13 +78,30 @@ def __init__(self, flush_after=timedelta(0, 10), flush_first=True, max_size=20,
6578
the consumer receives
6679
:param max_size (int): the number of events in queue that will trigger
6780
the queue to be flushed asynchronously
68-
:param events_url: the Mixpanel API URL that track events will be sent to
69-
:param people_url: the Mixpanel API URL that people events will be sent to
81+
:param events_url: Mixpanel API URL that track events will be sent to
82+
:param people_url: Mixpanel API URL that people events will be sent to
83+
:param import_url: Mixpanel API URL that import events will be sent to
84+
:param request_timeout: Connection timeout in seconds
85+
:param groups_url: Mixpanel API URL that groups events will be sent to
86+
:param api_host: Mixpanel API domain for all requests unless overriden by above URLs
87+
:param retry_limit: Number of times to retry each request in case of an error, 0
88+
to fail after first attempt.
89+
:param retry_backoff_factor: Factor which controls sleep duration between retries:
90+
sleep_seconds = backoff_factor * (2 ^ (retry_count - 1))
91+
:param verify_cert: Whether to verify the server certificate. "True" is
92+
recommended.
7093
'''
7194
super(AsyncBufferedConsumer, self).__init__(
7295
max_size=max_size,
7396
events_url=events_url,
74-
people_url=people_url
97+
people_url=people_url,
98+
import_url=import_url,
99+
request_timeout=request_timeout,
100+
groups_url=groups_url,
101+
api_host=api_host,
102+
retry_limit=retry_limit,
103+
retry_backoff_factor=retry_backoff_factor,
104+
verify_cert=verify_cert,
75105
)
76106

77107
# remove the minimum max size that the SynchronousBufferedConsumer

0 commit comments

Comments
 (0)