-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor lbrynet-daemon into modular components (#1164)
* add daemon Component and ComponentManager classes * convert directory and SQLiteStorage setup to be a Component * support callbacks to component setups * Fixed typo in ComponentManager * convert wallet to be Component * Use storage from session. * Remove create_session internal function and PEP8 * Starting to convert session to its own component. Removed ref to `self.storage` from Daemon.py * Making DHT component(broken) * Refactored classes to reduce redundancy in getting config setting * DHT is now it's own component * Fixed `test_streamify` test * Fixed regression caused by removing `peer_manager` from session * refactor ComponentManager and Component to use instance instead of class methods * Hash announcer, file manager, stream identifier components * Query Handler and server components * Reflector Component * Fixed test_streamify(well Jack did, but ¯\_(ツ)_/¯) * All tests now passing * Pylint fixes * Oops(That's all you're gonna get :-P) * Making decorators(WIP, commit so that I don't lose work) * Decorator made and decorating of functions done(some other changes) * import fixes and removed temporary test function * Fixed new broken tests from daemon refactor * Sanitization of modules * Reworded errors * wallet unlock condition checks, fixed breaking changes * Rebased on amster and other crazy stuff * Started writing tests * Tests for component manager * Fix Daemon Tests * Fixed passing mutable args in init * Using constants instead of strings. Added CHANGELOG.md * Now components can be skipped by setting relevant config in file. * P-Y-L-I-N-T #angry_emoji
- Loading branch information
1 parent
148cc96
commit 75a6ff2
Showing
19 changed files
with
1,326 additions
and
662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import logging | ||
from twisted.internet import defer | ||
from ComponentManager import ComponentManager | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class ComponentType(type): | ||
def __new__(mcs, name, bases, newattrs): | ||
klass = type.__new__(mcs, name, bases, newattrs) | ||
if name != "Component": | ||
ComponentManager.default_component_classes[klass.component_name] = klass | ||
return klass | ||
|
||
|
||
class Component(object): | ||
""" | ||
lbrynet-daemon component helper | ||
Inheriting classes will be automatically registered with the ComponentManager and must implement setup and stop | ||
methods | ||
""" | ||
|
||
__metaclass__ = ComponentType | ||
depends_on = [] | ||
component_name = None | ||
|
||
def __init__(self, component_manager): | ||
self.component_manager = component_manager | ||
self._running = False | ||
|
||
@property | ||
def running(self): | ||
return self._running | ||
|
||
def start(self): | ||
raise NotImplementedError() | ||
|
||
def stop(self): | ||
raise NotImplementedError() | ||
|
||
def component(self): | ||
raise NotImplementedError() | ||
|
||
@defer.inlineCallbacks | ||
def _setup(self): | ||
try: | ||
result = yield defer.maybeDeferred(self.start) | ||
self._running = True | ||
defer.returnValue(result) | ||
except Exception as err: | ||
log.exception("Error setting up %s", self.component_name or self.__class__.__name__) | ||
raise err | ||
|
||
@defer.inlineCallbacks | ||
def _stop(self): | ||
try: | ||
result = yield defer.maybeDeferred(self.stop) | ||
self._running = False | ||
defer.returnValue(result) | ||
except Exception as err: | ||
log.exception("Error stopping %s", self.__class__.__name__) | ||
raise err |
Oops, something went wrong.