forked from LBRYCommunity/lbry-sdk
move LoopingCallManager to own module
This commit is contained in:
parent
d5f0001950
commit
ddb88eb1c9
2 changed files with 26 additions and 22 deletions
22
lbrynet/core/looping_call_manager.py
Normal file
22
lbrynet/core/looping_call_manager.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
|
||||
class LoopingCallManager(object):
|
||||
def __init__(self):
|
||||
self.calls = {}
|
||||
|
||||
def register_looping_call(self, name, call):
|
||||
assert name not in self.calls, '{} is already registered'.format(name)
|
||||
self.calls[name] = call
|
||||
|
||||
def start(self, name, *args):
|
||||
lcall = self.calls[name]
|
||||
if not lcall.running:
|
||||
lcall.start(*args)
|
||||
|
||||
def stop(self, name):
|
||||
self.calls[name].stop()
|
||||
|
||||
def shutdown(self):
|
||||
for lcall in self.calls.itervalues():
|
||||
if lcall.running:
|
||||
lcall.stop()
|
|
@ -28,6 +28,9 @@ from lbrynet import __version__ as lbrynet_version
|
|||
# TODO: importing this when internet is disabled raises a socket.gaierror
|
||||
from lbryum.version import LBRYUM_VERSION as lbryum_version
|
||||
from lbrynet import analytics
|
||||
from lbrynet.core.looping_call_manager import LoopingCallManager
|
||||
from lbrynet.core.PaymentRateManager import PaymentRateManager
|
||||
from lbrynet.core.server.BlobAvailabilityHandler import BlobAvailabilityHandlerFactory
|
||||
from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory
|
||||
from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
|
||||
from lbrynet.core.Error import UnknownNameError, InsufficientFundsError, InvalidNameError
|
||||
|
@ -135,27 +138,6 @@ class Parameters(object):
|
|||
self.__dict__.update(kwargs)
|
||||
|
||||
|
||||
class LoopingCallManager(object):
|
||||
def __init__(self):
|
||||
self.calls = {}
|
||||
|
||||
def register_looping_call(self, name, *args):
|
||||
self.calls[name] = LoopingCall(*args)
|
||||
|
||||
def start(self, name, *args):
|
||||
lcall = self.calls[name]
|
||||
if not lcall.running:
|
||||
lcall.start(*args)
|
||||
|
||||
def stop(self, name):
|
||||
self.calls[name].stop()
|
||||
|
||||
def shutdown(self):
|
||||
for lcall in self.calls.itervalues():
|
||||
if lcall.running:
|
||||
lcall.stop()
|
||||
|
||||
|
||||
class CheckInternetConnection(object):
|
||||
def __init__(self, daemon):
|
||||
self.daemon = daemon
|
||||
|
@ -422,7 +404,7 @@ class Daemon(jsonrpc.JSONRPC):
|
|||
('pending_claim_checker', self._check_pending_claims),
|
||||
]
|
||||
for name, fn in looping_calls:
|
||||
self.looping_call_manager.register_looping_call(name, fn)
|
||||
self.looping_call_manager.register_looping_call(name, LoopingCall(fn))
|
||||
|
||||
self.sd_identifier = StreamDescriptorIdentifier()
|
||||
self.stream_info_manager = TempEncryptedFileMetadataManager()
|
||||
|
|
Loading…
Reference in a new issue