Merge pull request #375 from lbryio/fix-stop-errors

Fix stop errors
This commit is contained in:
Job Evers‐Meltzer 2017-01-03 14:13:24 -06:00 committed by GitHub
commit f8f83fccf1

View file

@ -1565,6 +1565,7 @@ class Daemon(AuthJSONRPCServer):
defer.returnValue(response) defer.returnValue(response)
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
@defer.inlineCallbacks
def jsonrpc_stop_lbry_file(self, p): def jsonrpc_stop_lbry_file(self, p):
""" """
Stop lbry file Stop lbry file
@ -1576,25 +1577,16 @@ class Daemon(AuthJSONRPCServer):
Returns: Returns:
confirmation message confirmation message
""" """
searchtype, value = get_lbry_file_search_value(p)
def _stop_file(f): lbry_file = yield self._get_lbry_file(searchtype, value, return_json=False)
if f.stopped: if not lbry_file:
return "LBRY file wasn't running" raise Exception('Unable to find a file for {}:{}'.format(searchtype, value))
else: if lbry_file.stopped:
d = self.lbry_file_manager.toggle_lbry_file_running(f) msg = "LBRY file wasn't running"
d.addCallback(lambda _: "Stopped LBRY file")
return d
try:
searchtype, value = get_lbry_file_search_value(p)
except NoValidSearch:
d = defer.fail()
else: else:
d = self._get_lbry_file(searchtype, value, return_json=False) yield self.lbry_file_manager.toggle_lbry_file_running(lbry_file)
d.addCallback(_stop_file) msg = "Stopped LBRY file"
defer.returnValue(self._render_response(msg, OK_CODE))
d.addCallback(lambda r: self._render_response(r, OK_CODE))
return d
@AuthJSONRPCServer.auth_required @AuthJSONRPCServer.auth_required
def jsonrpc_start_lbry_file(self, p): def jsonrpc_start_lbry_file(self, p):
@ -2682,7 +2674,7 @@ def get_lbry_file_search_value(p):
value = p.get(searchtype) value = p.get(searchtype)
if value: if value:
return searchtype, value return searchtype, value
raise NoValidSearch() raise NoValidSearch('{} is missing a valid search type'.format(p))
def run_reflector_factory(factory): def run_reflector_factory(factory):