forked from M-Labs/artiq
1
0
Fork 0

browser: add update method to dataset controller

This commit is contained in:
Florian Agbuya 2023-06-06 18:59:01 +08:00 committed by Sébastien Bourdeauducq
parent bf46ce4a92
commit 7ad32d903a
1 changed files with 19 additions and 6 deletions

View File

@ -28,21 +28,34 @@ class DatasetCtl:
self.master_host = master_host self.master_host = master_host
self.master_port = master_port self.master_port = master_port
async def set(self, key, value, persist=None): async def _execute_rpc(self, op_name, key_or_mod, value=None, persist=None):
logger.info("Uploading dataset '%s' to master...", key) logger.info("Starting %s operation on %s", op_name, key_or_mod)
try: try:
remote = RPCClient() remote = RPCClient()
await remote.connect_rpc(self.master_host, self.master_port, await remote.connect_rpc(self.master_host, self.master_port,
"master_dataset_db") "master_dataset_db")
try: try:
await remote.set(key, value, persist) if op_name == "set":
await remote.set(key_or_mod, value, persist)
elif op_name == "update":
await remote.update(key_or_mod)
else:
logger.error("Invalid operation: %s", op_name)
return
finally: finally:
remote.close_rpc() remote.close_rpc()
except: except:
logger.error("Failed uploading dataset '%s'", logger.error("Failed %s operation on %s", op_name,
key, exc_info=True) key_or_mod, exc_info=True)
else: else:
logger.info("Finished uploading dataset '%s'", key) logger.info("Finished %s operation on %s", op_name,
key_or_mod)
async def set(self, key, value, persist=None):
await self._execute_rpc("set", key, value, persist)
async def update(self, mod):
await self._execute_rpc("update", mod)
class DatasetsDock(QtWidgets.QDockWidget): class DatasetsDock(QtWidgets.QDockWidget):