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):
|
||||
return self._event('Heartbeat')
|
||||
|
||||
def download_started(self, name, stream_info=None):
|
||||
properties = {
|
||||
'name': name,
|
||||
'stream_info': get_sd_hash(stream_info)
|
||||
}
|
||||
def download_started(self, *args, **kwargs):
|
||||
properties = download_properties(*args, **kwargs)
|
||||
return self._event('Download Started', properties)
|
||||
|
||||
def download_errored(self, name, stream_info=None):
|
||||
properties = {
|
||||
'name': name,
|
||||
'stream_info': get_sd_hash(stream_info)
|
||||
}
|
||||
def download_errored(self, *args, **kwargs):
|
||||
properties = download_properties(*args, **kwargs)
|
||||
return self._event('Download Errored', properties)
|
||||
|
||||
def download_finished(self, name, stream_info=None):
|
||||
properties = {
|
||||
'name': name,
|
||||
'stream_info': get_sd_hash(stream_info)
|
||||
}
|
||||
def download_finished(self, *args, **kwargs):
|
||||
properties = download_properties(*args, **kwargs)
|
||||
return self._event('Download Finished', properties)
|
||||
|
||||
def error(self, message, sd_hash=None):
|
||||
|
@ -124,3 +115,11 @@ def make_context(platform, wallet):
|
|||
'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)
|
||||
self.analytics_api.track(event)
|
||||
|
||||
def send_download_started(self, name, stream_info=None):
|
||||
event = self.events_generator.download_started(name, stream_info)
|
||||
def send_download_started(self, id_, name, stream_info=None):
|
||||
event = self.events_generator.download_started(id_, name, stream_info)
|
||||
self.analytics_api.track(event)
|
||||
|
||||
def send_download_errored(self, name, stream_info=None):
|
||||
event = self.events_generator.download_errored(name, stream_info)
|
||||
def send_download_errored(self, id_, name, stream_info=None):
|
||||
event = self.events_generator.download_errored(id_, name, stream_info)
|
||||
self.analytics_api.track(event)
|
||||
|
||||
def send_download_finished(self, name, stream_info=None):
|
||||
event = self.events_generator.download_finished(name, stream_info)
|
||||
def send_download_finished(self, id_, name, stream_info=None):
|
||||
event = self.events_generator.download_finished(id_, name, stream_info)
|
||||
self.analytics_api.track(event)
|
||||
|
||||
def send_error(self, message, sd_hash=None):
|
||||
|
|
|
@ -4,6 +4,7 @@ import logging
|
|||
import random
|
||||
import os
|
||||
import socket
|
||||
import string
|
||||
import sys
|
||||
|
||||
import pkg_resources
|
||||
|
@ -92,3 +93,7 @@ def setup_certs_for_windows():
|
|||
if getattr(sys, 'frozen', False) and os.name == "nt":
|
||||
cert_path = os.path.join(os.path.dirname(sys.executable), "cacert.pem")
|
||||
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)
|
||||
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:
|
||||
sd_hash, file_path = yield self._download_name(
|
||||
name=params.name,
|
||||
|
@ -1529,7 +1530,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
wait_for_write=params.wait_for_write
|
||||
)
|
||||
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)
|
||||
response = yield self._render_response(str(e), OK_CODE)
|
||||
else:
|
||||
|
@ -1541,7 +1542,9 @@ class Daemon(AuthJSONRPCServer):
|
|||
stream = self.streams.get(name)
|
||||
if stream:
|
||||
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)
|
||||
defer.returnValue(response)
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ class EventsTest(unittest.TestCase):
|
|||
self.assertEqual(desired_result, result)
|
||||
|
||||
def test_download_started(self):
|
||||
result = self.event_generator.download_started('great gatsby')
|
||||
result = self.event_generator.download_started('1', 'great gatsby')
|
||||
desired_result = {
|
||||
'context': 'any valid json datatype',
|
||||
'event': 'Download Started',
|
||||
|
@ -31,6 +31,7 @@ class EventsTest(unittest.TestCase):
|
|||
'session_id': 'session456',
|
||||
'name': 'great gatsby',
|
||||
'stream_info': None,
|
||||
'download_id': '1'
|
||||
},
|
||||
'timestamp': '2016-01-01T00:00:00Z',
|
||||
'userId': 'lbry'
|
||||
|
|
Loading…
Reference in a new issue