forked from LBRYCommunity/lbry-sdk
add id to link download events
This commit is contained in:
parent
6bdc9069c9
commit
669a567545
5 changed files with 33 additions and 25 deletions
|
@ -48,25 +48,16 @@ class Events(object):
|
||||||
def heartbeat(self):
|
def heartbeat(self):
|
||||||
return self._event('Heartbeat')
|
return self._event('Heartbeat')
|
||||||
|
|
||||||
def download_started(self, name, stream_info=None):
|
def download_started(self, *args, **kwargs):
|
||||||
properties = {
|
properties = download_properties(*args, **kwargs)
|
||||||
'name': name,
|
|
||||||
'stream_info': get_sd_hash(stream_info)
|
|
||||||
}
|
|
||||||
return self._event('Download Started', properties)
|
return self._event('Download Started', properties)
|
||||||
|
|
||||||
def download_errored(self, name, stream_info=None):
|
def download_errored(self, *args, **kwargs):
|
||||||
properties = {
|
properties = download_properties(*args, **kwargs)
|
||||||
'name': name,
|
|
||||||
'stream_info': get_sd_hash(stream_info)
|
|
||||||
}
|
|
||||||
return self._event('Download Errored', properties)
|
return self._event('Download Errored', properties)
|
||||||
|
|
||||||
def download_finished(self, name, stream_info=None):
|
def download_finished(self, *args, **kwargs):
|
||||||
properties = {
|
properties = download_properties(*args, **kwargs)
|
||||||
'name': name,
|
|
||||||
'stream_info': get_sd_hash(stream_info)
|
|
||||||
}
|
|
||||||
return self._event('Download Finished', properties)
|
return self._event('Download Finished', properties)
|
||||||
|
|
||||||
def error(self, message, sd_hash=None):
|
def error(self, message, sd_hash=None):
|
||||||
|
@ -124,3 +115,11 @@ def make_context(platform, wallet):
|
||||||
'version': '1.0.0'
|
'version': '1.0.0'
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def download_properties(id_, name, stream_info=None):
|
||||||
|
return {
|
||||||
|
'download_id': id_,
|
||||||
|
'name': name,
|
||||||
|
'stream_info': get_sd_hash(stream_info)
|
||||||
|
}
|
||||||
|
|
|
@ -70,16 +70,16 @@ class Manager(object):
|
||||||
event = self.events_generator.server_startup_error(message)
|
event = self.events_generator.server_startup_error(message)
|
||||||
self.analytics_api.track(event)
|
self.analytics_api.track(event)
|
||||||
|
|
||||||
def send_download_started(self, name, stream_info=None):
|
def send_download_started(self, id_, name, stream_info=None):
|
||||||
event = self.events_generator.download_started(name, stream_info)
|
event = self.events_generator.download_started(id_, name, stream_info)
|
||||||
self.analytics_api.track(event)
|
self.analytics_api.track(event)
|
||||||
|
|
||||||
def send_download_errored(self, name, stream_info=None):
|
def send_download_errored(self, id_, name, stream_info=None):
|
||||||
event = self.events_generator.download_errored(name, stream_info)
|
event = self.events_generator.download_errored(id_, name, stream_info)
|
||||||
self.analytics_api.track(event)
|
self.analytics_api.track(event)
|
||||||
|
|
||||||
def send_download_finished(self, name, stream_info=None):
|
def send_download_finished(self, id_, name, stream_info=None):
|
||||||
event = self.events_generator.download_finished(name, stream_info)
|
event = self.events_generator.download_finished(id_, name, stream_info)
|
||||||
self.analytics_api.track(event)
|
self.analytics_api.track(event)
|
||||||
|
|
||||||
def send_error(self, message, sd_hash=None):
|
def send_error(self, message, sd_hash=None):
|
||||||
|
|
|
@ -4,6 +4,7 @@ import logging
|
||||||
import random
|
import random
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
|
import string
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
@ -92,3 +93,7 @@ def setup_certs_for_windows():
|
||||||
if getattr(sys, 'frozen', False) and os.name == "nt":
|
if getattr(sys, 'frozen', False) and os.name == "nt":
|
||||||
cert_path = os.path.join(os.path.dirname(sys.executable), "cacert.pem")
|
cert_path = os.path.join(os.path.dirname(sys.executable), "cacert.pem")
|
||||||
os.environ["REQUESTS_CA_BUNDLE"] = cert_path
|
os.environ["REQUESTS_CA_BUNDLE"] = cert_path
|
||||||
|
|
||||||
|
|
||||||
|
def random_string(length=10, chars=string.ascii_lowercase):
|
||||||
|
return ''.join([random.choice(chars) for _ in range(length)])
|
||||||
|
|
|
@ -1518,7 +1518,8 @@ class Daemon(AuthJSONRPCServer):
|
||||||
response = yield self._render_response(message, OK_CODE)
|
response = yield self._render_response(message, OK_CODE)
|
||||||
defer.returnValue(response)
|
defer.returnValue(response)
|
||||||
|
|
||||||
self.analytics_manager.send_download_started(name, stream_info)
|
download_id = utils.random_string()
|
||||||
|
self.analytics_manager.send_download_started(download_id, name, stream_info)
|
||||||
try:
|
try:
|
||||||
sd_hash, file_path = yield self._download_name(
|
sd_hash, file_path = yield self._download_name(
|
||||||
name=params.name,
|
name=params.name,
|
||||||
|
@ -1529,7 +1530,7 @@ class Daemon(AuthJSONRPCServer):
|
||||||
wait_for_write=params.wait_for_write
|
wait_for_write=params.wait_for_write
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.analytics_manager.send_download_errored(name, stream_info)
|
self.analytics_manager.send_download_errored(download_id, name, stream_info)
|
||||||
log.exception('Failed to get %s', params.name)
|
log.exception('Failed to get %s', params.name)
|
||||||
response = yield self._render_response(str(e), OK_CODE)
|
response = yield self._render_response(str(e), OK_CODE)
|
||||||
else:
|
else:
|
||||||
|
@ -1541,7 +1542,9 @@ class Daemon(AuthJSONRPCServer):
|
||||||
stream = self.streams.get(name)
|
stream = self.streams.get(name)
|
||||||
if stream:
|
if stream:
|
||||||
stream.downloader.finished_deferred.addCallback(
|
stream.downloader.finished_deferred.addCallback(
|
||||||
lambda _: self.analytics_manager.send_download_finished(name, stream_info))
|
lambda _: self.analytics_manager.send_download_finished(
|
||||||
|
download_id, name, stream_info)
|
||||||
|
)
|
||||||
response = yield self._render_response(message, OK_CODE)
|
response = yield self._render_response(message, OK_CODE)
|
||||||
defer.returnValue(response)
|
defer.returnValue(response)
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class EventsTest(unittest.TestCase):
|
||||||
self.assertEqual(desired_result, result)
|
self.assertEqual(desired_result, result)
|
||||||
|
|
||||||
def test_download_started(self):
|
def test_download_started(self):
|
||||||
result = self.event_generator.download_started('great gatsby')
|
result = self.event_generator.download_started('1', 'great gatsby')
|
||||||
desired_result = {
|
desired_result = {
|
||||||
'context': 'any valid json datatype',
|
'context': 'any valid json datatype',
|
||||||
'event': 'Download Started',
|
'event': 'Download Started',
|
||||||
|
@ -31,6 +31,7 @@ class EventsTest(unittest.TestCase):
|
||||||
'session_id': 'session456',
|
'session_id': 'session456',
|
||||||
'name': 'great gatsby',
|
'name': 'great gatsby',
|
||||||
'stream_info': None,
|
'stream_info': None,
|
||||||
|
'download_id': '1'
|
||||||
},
|
},
|
||||||
'timestamp': '2016-01-01T00:00:00Z',
|
'timestamp': '2016-01-01T00:00:00Z',
|
||||||
'userId': 'lbry'
|
'userId': 'lbry'
|
||||||
|
|
Loading…
Reference in a new issue