refactor analytics manager to use dependency injection
This commit is contained in:
parent
9da1b3c5b7
commit
4a07b56e8a
2 changed files with 15 additions and 17 deletions
|
@ -1,25 +1,17 @@
|
|||
import base58
|
||||
|
||||
from twisted.internet import task
|
||||
|
||||
import api
|
||||
import constants
|
||||
import events
|
||||
import track
|
||||
|
||||
|
||||
class Manager(object):
|
||||
def __init__(self):
|
||||
self.analytics_api = None
|
||||
self.events_generator = None
|
||||
self.track = track.Track()
|
||||
def __init__(self, analytics_api, events_generator, track):
|
||||
self.analytics_api = analytics_api
|
||||
self.events_generator = events_generator
|
||||
self.track = track
|
||||
self.send_heartbeat = task.LoopingCall(self._send_heartbeat)
|
||||
self.update_tracked_metrics = task.LoopingCall(self._update_tracked_metrics)
|
||||
|
||||
def start(self, platform, wallet_type, lbry_id, session_id):
|
||||
context = events.make_context(platform, wallet_type)
|
||||
self.events_generator = events.Events(context, base58.b58encode(lbry_id), session_id)
|
||||
self.analytics_api = api.Api.load()
|
||||
def start(self):
|
||||
self.send_heartbeat.start(60)
|
||||
self.update_tracked_metrics.start(300)
|
||||
|
||||
|
|
|
@ -244,7 +244,6 @@ class Daemon(jsonrpc.JSONRPC):
|
|||
self.first_run_after_update = False
|
||||
self.uploaded_temp_files = []
|
||||
self._session_id = base58.b58encode(generate_id())
|
||||
self.analytics_manager = analytics.Manager()
|
||||
|
||||
if os.name == "nt":
|
||||
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
|
||||
|
@ -613,6 +612,7 @@ class Daemon(jsonrpc.JSONRPC):
|
|||
d.addCallback(lambda _: self._check_db_migration())
|
||||
d.addCallback(lambda _: self._get_settings())
|
||||
d.addCallback(lambda _: self._get_session())
|
||||
d.addCallback(lambda _: self._get_analytics())
|
||||
d.addCallback(lambda _: add_lbry_file_to_sd_identifier(self.sd_identifier))
|
||||
d.addCallback(lambda _: self._setup_stream_identifier())
|
||||
d.addCallback(lambda _: self._setup_lbry_file_manager())
|
||||
|
@ -620,9 +620,6 @@ class Daemon(jsonrpc.JSONRPC):
|
|||
d.addCallback(lambda _: self._setup_server())
|
||||
d.addCallback(lambda _: _log_starting_vals())
|
||||
d.addCallback(lambda _: _announce_startup())
|
||||
d.addCallback(
|
||||
lambda _: self.analytics_manager.start(
|
||||
self._get_platform(), self.wallet_type, self.lbryid, self._session_id))
|
||||
# TODO: handle errors here
|
||||
d.callback(None)
|
||||
|
||||
|
@ -1034,6 +1031,15 @@ class Daemon(jsonrpc.JSONRPC):
|
|||
|
||||
return d
|
||||
|
||||
def _get_analytics(self):
|
||||
analytics_api = analytics.Api.load()
|
||||
context = analytics.make_context(self._get_platform(), self.wallet_type)
|
||||
events_generator = analytics.Events(
|
||||
context, base58.b58encode(self.lbryid), self._session_id)
|
||||
self.analytics_manager = analytics.Manager(
|
||||
analytics_api, events_generator, analytics.Track())
|
||||
self.analytics_manager.start()
|
||||
|
||||
def _get_session(self):
|
||||
def get_default_data_rate():
|
||||
d = self.settings.get_default_data_payment_rate()
|
||||
|
|
Loading…
Add table
Reference in a new issue