refactor status results

This commit is contained in:
Jack Robison 2018-08-02 17:33:56 -04:00
parent 4ef4a4816f
commit aef561d78b
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
3 changed files with 42 additions and 18 deletions

View file

@ -360,6 +360,16 @@ class BlobComponent(Component):
def stop(self): def stop(self):
return self.blob_manager.stop() return self.blob_manager.stop()
@defer.inlineCallbacks
def get_status(self):
if not self.blob_manager:
count = 0
else:
count = yield self.blob_manager.storage.count_finished_blobs()
defer.returnValue({
'finished_blobs': count
})
class DHTComponent(Component): class DHTComponent(Component):
component_name = DHT_COMPONENT component_name = DHT_COMPONENT
@ -432,6 +442,11 @@ class HashAnnouncerComponent(Component):
def stop(self): def stop(self):
yield self.hash_announcer.stop() yield self.hash_announcer.stop()
def get_status(self):
return {
'announce_queue_size': 0 if not self.hash_announcer else len(self.hash_announcer.hash_queue)
}
class RateLimiterComponent(Component): class RateLimiterComponent(Component):
component_name = RATE_LIMITER_COMPONENT component_name = RATE_LIMITER_COMPONENT
@ -523,7 +538,7 @@ class FileManagerComponent(Component):
if not self.file_manager: if not self.file_manager:
return return
return { return {
'managed_streams': len(self.file_manager.lbry_files) 'managed_files': len(self.file_manager.lbry_files)
} }
@defer.inlineCallbacks @defer.inlineCallbacks

View file

@ -90,7 +90,7 @@ class IterableContainer(object):
class Checker(object): class Checker(object):
"""The looping calls the daemon runs""" """The looping calls the daemon runs"""
INTERNET_CONNECTION = 'internet_connection_checker', 3600 INTERNET_CONNECTION = 'internet_connection_checker', 300
# CONNECTION_STATUS = 'connection_status_checker' # CONNECTION_STATUS = 'connection_status_checker'
@ -659,15 +659,12 @@ class Daemon(AuthJSONRPCServer):
############################################################################ ############################################################################
@defer.inlineCallbacks @defer.inlineCallbacks
def jsonrpc_status(self, session_status=False): def jsonrpc_status(self):
""" """
Get daemon status Get daemon status
Usage: Usage:
status [--session_status] status
Options:
--session_status : (bool) include session status in results
Returns: Returns:
(dict) lbrynet-daemon status (dict) lbrynet-daemon status
@ -684,6 +681,8 @@ class Daemon(AuthJSONRPCServer):
'hash_announcer': (bool), 'hash_announcer': (bool),
'stream_identifier': (bool), 'stream_identifier': (bool),
'file_manager': (bool), 'file_manager': (bool),
'blob_manager': (bool),
'blockchain_headers': (bool),
'peer_protocol_server': (bool), 'peer_protocol_server': (bool),
'reflector': (bool), 'reflector': (bool),
'upnp': (bool), 'upnp': (bool),
@ -693,27 +692,33 @@ class Daemon(AuthJSONRPCServer):
'code': (str) connection status code, 'code': (str) connection status code,
'message': (str) connection status message 'message': (str) connection status message
}, },
'blockchain_status': { 'blockchain_headers': {
'downloading_headers': (bool),
'download_progress': (float) 0-100.0
},
'wallet': {
'blocks': (int) local blockchain height, 'blocks': (int) local blockchain height,
'blocks_behind': (int) remote_height - local_height, 'blocks_behind': (int) remote_height - local_height,
'best_blockhash': (str) block hash of most recent block, 'best_blockhash': (str) block hash of most recent block,
'is_encrypted': (bool)
}, },
'dht': { 'dht': {
'node_id': (str) lbry dht node id - hex encoded, 'node_id': (str) lbry dht node id - hex encoded,
'peers_in_routing_table': (int) the number of peers in the routing table, 'peers_in_routing_table': (int) the number of peers in the routing table,
}, },
'wallet_is_encrypted': (bool), 'blob_manager': {
If given the session status option: 'finished_blobs': (int) number of finished blobs in the blob manager,
'session_status': { },
'managed_blobs': (int) count of blobs in the blob manager, 'hash_announcer': {
'managed_streams': (int) count of streams in the file manager, 'announce_queue_size': (int) number of blobs currently queued to be announced
'announce_queue_size': (int) number of blobs currently queued to be announced, },
'should_announce_blobs': (int) number of blobs that should be announced, 'file_manager': {
} 'managed_files': (int) count of files in the file manager,
}
} }
""" """
connection_code = CONNECTION_STATUS_CONNECTED if utils.check_connection() else CONNECTION_STATUS_NETWORK connection_code = CONNECTION_STATUS_CONNECTED if self.connected_to_internet else CONNECTION_STATUS_NETWORK
response = { response = {
'installation_id': conf.settings.installation_id, 'installation_id': conf.settings.installation_id,
'is_running': all(self.component_manager.get_components_status().values()), 'is_running': all(self.component_manager.get_components_status().values()),
@ -729,7 +734,6 @@ class Daemon(AuthJSONRPCServer):
status = yield defer.maybeDeferred(component.get_status) status = yield defer.maybeDeferred(component.get_status)
if status: if status:
response[component.component_name] = status response[component.component_name] = status
defer.returnValue(response) defer.returnValue(response)
def jsonrpc_version(self): def jsonrpc_version(self):

View file

@ -261,6 +261,11 @@ class SQLiteStorage(object):
) )
defer.returnValue([blob_hash.decode('hex') for blob_hash in blob_hashes]) defer.returnValue([blob_hash.decode('hex') for blob_hash in blob_hashes])
def count_finished_blobs(self):
return self.run_and_return_one_or_none(
"select count(*) from blob where status='finished'"
)
def update_last_announced_blob(self, blob_hash, last_announced): def update_last_announced_blob(self, blob_hash, last_announced):
return self.db.runOperation( return self.db.runOperation(
"update blob set next_announce_time=?, last_announced_time=?, single_announce=0 where blob_hash=?", "update blob set next_announce_time=?, last_announced_time=?, single_announce=0 where blob_hash=?",