Skip to content

Commit

Permalink
Merge branch 'release/0.8.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhanunlu committed Jun 28, 2019
2 parents 4550310 + 47659e6 commit 54407a9
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 262 deletions.
10 changes: 10 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Version 0.8.3 (2019-06-28)
--------------------------
Fix test_bytelimit test (#227)
Initialize Celery in CeleryEmitter (#226)
Allow non ascii characters to be encoded using Base64 (#194)
Allow empty strings in string_or_none contract (#184)
Fix on_failure param docstring description (#225)
Bump max version requirement of redis (#223)
Remove Vagrant & Ansible (#222)

Version 0.8.2 (2018-12-01)
--------------------------
Fix date for 0.8.0 release in CHANGELOG (#183)
Expand Down
32 changes: 12 additions & 20 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
======================================================
Python Analytics for Snowplow
======================================================
.. image:: https://travis-ci.org/snowplow/snowplow-python-tracker.png?branch=master
.. image:: https://travis-ci.org/snowplow/snowplow-python-tracker.svg?branch=master
:alt: Build Status
:target: https://travis-ci.org/snowplow/snowplow-python-tracker
.. image:: https://badge.fury.io/py/snowplow-tracker.png
.. image:: https://badge.fury.io/py/snowplow-tracker.svg
:target: http://badge.fury.io/py/snowplow-tracker
.. image:: https://coveralls.io/repos/snowplow/snowplow-python-tracker/badge.png
:target: https://coveralls.io/r/snowplow/snowplow-python-tracker
.. image:: https://coveralls.io/repos/github/snowplow/snowplow-python-tracker/badge.svg?branch=master
:target: https://coveralls.io/github/snowplow/snowplow-python-tracker?branch=master
.. image:: http://img.shields.io/badge/license-Apache--2-blue.svg?style=flat
:target: http://www.apache.org/licenses/LICENSE-2.0

Expand Down Expand Up @@ -46,33 +46,25 @@ Find out more
.. _`Roadmap`: https://github.com/snowplow/snowplow/wiki/Python-Tracker-Roadmap
.. _`Contributing`: https://github.com/snowplow/snowplow/wiki/Python-Tracker-Contributing

Contributing quickstart
Quickstart
#######################

Assuming Git, Vagrant_ and VirtualBox_ are installed:
Assuming pyenv_ is installed

::

host$ git clone [email protected]:snowplow/snowplow-python-tracker.git
host$ vagrant up && vagrant ssh
guest$ cd /vagrant
guest$ ./run-tests.sh deploy
guest$ ./run-tests.sh test
host$ cd snowplow-python-tracker
host$ pyenv install 2.7.15 && pyenv install 3.4.9 && pyenv install 3.5.2 && pyenv install 3.7.1
host$ ./run-tests.sh deploy
host$ ./run-tests.sh test

.. _Vagrant: http://docs.vagrantup.com/v2/installation/index.html
.. _VirtualBox: https://www.virtualbox.org/wiki/Downloads

Publishing
##########

::

host$ vagrant push
.. _pyenv: https://github.com/pyenv/pyenv

Copyright and license
#####################

The Snowplow Python Tracker is copyright 2013-2014 Snowplow Analytics Ltd.
The Snowplow Python Tracker is copyright 2013-2019 Snowplow Analytics Ltd.

Licensed under the `Apache License, Version 2.0`_ (the "License");
you may not use this software except in compliance with the License.
Expand Down
23 changes: 0 additions & 23 deletions Vagrantfile

This file was deleted.

6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
setup.py
Copyright (c) 2013-2014 Snowplow Analytics Ltd. All rights reserved.
Copyright (c) 2013-2019 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License
Expand All @@ -15,7 +15,7 @@
language governing permissions and limitations there under.
Authors: Anuj More, Alex Dean, Fred Blundun
Copyright: Copyright (c) 2013-2014 Snowplow Analytics Ltd
Copyright: Copyright (c) 2013-2019 Snowplow Analytics Ltd
License: Apache License Version 2.0
"""

Expand Down Expand Up @@ -80,7 +80,7 @@
"pycontracts>=1.7.6,<2.0",
"celery>=4.0,<5.0",
"gevent>=1.0.2,<2.0",
"redis>=2.9.1,<3.0",
"redis>=2.9.1,<4.0",
"six>=1.9.0,<2.0"
],
)
6 changes: 3 additions & 3 deletions snowplow_tracker/_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
_version.py
Copyright (c) 2013-2014 Snowplow Analytics Ltd. All rights reserved.
Copyright (c) 2013-2019 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License
Expand All @@ -15,11 +15,11 @@
language governing permissions and limitations there under.
Authors: Anuj More, Alex Dean, Fred Blundun
Copyright: Copyright (c) 2013-2016 Snowplow Analytics Ltd
Copyright: Copyright (c) 2013-2019 Snowplow Analytics Ltd
License: Apache License Version 2.0
"""


__version_info__ = (0, 8, 2)
__version_info__ = (0, 8, 3)
__version__ = ".".join(str(x) for x in __version_info__)
__build_version__ = __version__ + ''
44 changes: 21 additions & 23 deletions snowplow_tracker/emitters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
emitters.py
Copyright (c) 2013-2014 Snowplow Analytics Ltd. All rights reserved.
Copyright (c) 2013-2019 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License
Expand All @@ -15,7 +15,7 @@
language governing permissions and limitations there under.
Authors: Anuj More, Alex Dean, Fred Blundun
Copyright: Copyright (c) 2013-2014 Snowplow Analytics Ltd
Copyright: Copyright (c) 2013-2019 Snowplow Analytics Ltd
License: Apache License Version 2.0
"""

Expand Down Expand Up @@ -51,16 +51,6 @@

new_contract("redis", lambda x: isinstance(x, (redis.Redis, redis.StrictRedis)))

try:
# Check whether a custom Celery configuration module named "snowplow_celery_config" exists
import snowplow_celery_config
app = Celery()
app.config_from_object(snowplow_celery_config)
except ImportError:
# Otherwise configure Celery with default settings
snowplow_celery_config = None
app = Celery("Snowplow", broker="redis://guest@localhost//")


class Emitter(object):
"""
Expand All @@ -84,7 +74,7 @@ def __init__(self, endpoint, protocol="http", port=None, method="get", buffer_si
:param on_success: Callback executed after every HTTP request in a flush has status code 200
Gets passed the number of events flushed.
:type on_success: function | None
:param on_failure: Callback executed if at least one HTTP request in a flush has status code 200
:param on_failure: Callback executed if at least one HTTP request in a flush has status code other than 200
Gets passed two arguments:
1) The number of events which were successfully sent
2) If method is "post": The unsent data in string form;
Expand Down Expand Up @@ -342,7 +332,7 @@ def __init__(
:param on_success: Callback executed after every HTTP request in a flush has status code 200
Gets passed the number of events flushed.
:type on_success: function | None
:param on_failure: Callback executed if at least one HTTP request in a flush has status code 200
:param on_failure: Callback executed if at least one HTTP request in a flush has status code other than 200
Gets passed two arguments:
1) The number of events which were successfully sent
2) If method is "post": The unsent data in string form;
Expand Down Expand Up @@ -385,30 +375,38 @@ def consume(self):
self.queue.task_done()


@app.task(bind=True, name='tasks.flush') # the self passed with bind can be used for on_fail/retrying
def flush_emitter(self, emitter):
try:
emitter.flush()
finally:
logger.info("Flush called on emitter")


class CeleryEmitter(Emitter):
"""
Uses a Celery worker to send HTTP requests asynchronously.
Works like the base Emitter class,
but on_success and on_failure callbacks cannot be set.
"""
celery_app = None

def __init__(self, endpoint, protocol="http", port=None, method="get", buffer_size=None, byte_limit=None):
super(CeleryEmitter, self).__init__(endpoint, protocol, port, method, buffer_size, None, None, byte_limit)

try:
# Check whether a custom Celery configuration module named "snowplow_celery_config" exists
import snowplow_celery_config
self.celery_app = Celery()
self.celery_app.config_from_object(snowplow_celery_config)
except ImportError:
# Otherwise configure Celery with default settings
self.celery_app = Celery("Snowplow", broker="redis://guest@localhost//")

self.async_flush = self.celery_app.task(self.async_flush)

def flush(self):
"""
Schedules a flush task
"""
flush_emitter.delay(self) # passes emitter (self - CeleryEmitter) to task
self.async_flush.delay()
logger.info("Scheduled a Celery task to flush the event queue")

def async_flush(self):
super(CeleryEmitter, self).flush()


class RedisEmitter(object):
"""
Expand Down
6 changes: 3 additions & 3 deletions snowplow_tracker/payload.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
payload.py
Copyright (c) 2013-2014 Snowplow Analytics Ltd. All rights reserved.
Copyright (c) 2013-2019 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License
Expand All @@ -15,7 +15,7 @@
language governing permissions and limitations there under.
Authors: Anuj More, Alex Dean, Fred Blundun
Copyright: Copyright (c) 2013-2014 Snowplow Analytics Ltd
Copyright: Copyright (c) 2013-2019 Snowplow Analytics Ltd
License: Apache License Version 2.0
"""

Expand Down Expand Up @@ -82,7 +82,7 @@ def add_json(self, dict_, encode_base64, type_when_encoded, type_when_not_encode
json_dict = json.dumps(dict_, ensure_ascii=False)

if encode_base64:
encoded_dict = base64.urlsafe_b64encode(json_dict.encode("ascii"))
encoded_dict = base64.urlsafe_b64encode(json_dict.encode("utf-8"))
if not isinstance(encoded_dict, str):
encoded_dict = encoded_dict.decode("utf-8")
self.add(type_when_encoded, encoded_dict)
Expand Down
4 changes: 2 additions & 2 deletions snowplow_tracker/redis_worker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
redis_worker.py
Copyright (c) 2013-2014 Snowplow Analytics Ltd. All rights reserved.
Copyright (c) 2013-2019 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License
Expand All @@ -15,7 +15,7 @@
language governing permissions and limitations there under.
Authors: Anuj More, Alex Dean, Fred Blundun
Copyright: Copyright (c) 2013-2014 Snowplow Analytics Ltd
Copyright: Copyright (c) 2013-2019 Snowplow Analytics Ltd
License: Apache License Version 2.0
"""

Expand Down
4 changes: 2 additions & 2 deletions snowplow_tracker/self_describing_json.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
self_describing_json.py
Copyright (c) 2013-2014 Snowplow Analytics Ltd. All rights reserved.
Copyright (c) 2013-2019 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License
Expand All @@ -15,7 +15,7 @@
language governing permissions and limitations there under.
Authors: Anuj More, Alex Dean, Fred Blundun
Copyright: Copyright (c) 2013-2014 Snowplow Analytics Ltd
Copyright: Copyright (c) 2013-2019 Snowplow Analytics Ltd
License: Apache License Version 2.0
"""

Expand Down
4 changes: 2 additions & 2 deletions snowplow_tracker/subject.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
subject.py
Copyright (c) 2013-2014 Snowplow Analytics Ltd. All rights reserved.
Copyright (c) 2013-2019 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License
Expand All @@ -15,7 +15,7 @@
language governing permissions and limitations there under.
Authors: Anuj More, Alex Dean, Fred Blundun
Copyright: Copyright (c) 2013-2014 Snowplow Analytics Ltd
Copyright: Copyright (c) 2013-2019 Snowplow Analytics Ltd
License: Apache License Version 2.0
"""

Expand Down
6 changes: 3 additions & 3 deletions snowplow_tracker/test/integration/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
test_integration.py
Copyright (c) 2013-2014 Snowplow Analytics Ltd. All rights reserved.
Copyright (c) 2013-2019 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License
Expand All @@ -15,7 +15,7 @@
language governing permissions and limitations there under.
Authors: Anuj More, Alex Dean, Fred Blundun
Copyright: Copyright (c) 2013-2014 Snowplow Analytics Ltd
Copyright: Copyright (c) 2013-2019 Snowplow Analytics Ltd
License: Apache License Version 2.0
"""

Expand Down Expand Up @@ -329,4 +329,4 @@ def test_bytelimit(self):
t.track_struct_event("Test", "A") # 420 bytes. Send
t.track_struct_event("Test", "AA") # 141
self.assertEquals(len(querystrings[-1]["data"]), 3)
self.assertEqual(post_emitter.bytes_queued, 141)
self.assertEqual(post_emitter.bytes_queued, 136 + len(_version.__version__))
4 changes: 2 additions & 2 deletions snowplow_tracker/test/unit/test_payload.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
test_payload.py
Copyright (c) 2013-2014 Snowplow Analytics Ltd. All rights reserved.
Copyright (c) 2013-2019 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License
Expand All @@ -15,7 +15,7 @@
language governing permissions and limitations there under.
Authors: Anuj More, Alex Dean, Fred Blundun
Copyright: Copyright (c) 2013-2014 Snowplow Analytics Ltd
Copyright: Copyright (c) 2013-2019 Snowplow Analytics Ltd
License: Apache License Version 2.0
"""

Expand Down
4 changes: 2 additions & 2 deletions snowplow_tracker/test/unit/test_tracker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
test_tracker.py
Copyright (c) 2013-2014 Snowplow Analytics Ltd. All rights reserved.
Copyright (c) 2013-2019 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License
Expand All @@ -15,7 +15,7 @@
language governing permissions and limitations there under.
Authors: Anuj More, Alex Dean, Fred Blundun
Copyright: Copyright (c) 2013-2014 Snowplow Analytics Ltd
Copyright: Copyright (c) 2013-2019 Snowplow Analytics Ltd
License: Apache License Version 2.0
"""

Expand Down
Loading

0 comments on commit 54407a9

Please sign in to comment.