master: merge master_config and master_terminate

This commit is contained in:
Sebastien Bourdeauducq 2023-05-30 15:55:19 +08:00
parent 444bab2186
commit 953a8a9555
3 changed files with 9 additions and 17 deletions

View File

@ -327,7 +327,7 @@ def main():
"scan_devices": "master_device_db", "scan_devices": "master_device_db",
"scan_repository": "master_experiment_db", "scan_repository": "master_experiment_db",
"ls": "master_experiment_db", "ls": "master_experiment_db",
"terminate": "master_terminate", "terminate": "master_management",
}[action] }[action]
remote = Client(args.server, port, target_name) remote = Client(args.server, port, target_name)
try: try:

View File

@ -125,11 +125,11 @@ def main():
atexit.register(client.close_rpc) atexit.register(client.close_rpc)
rpc_clients[target] = client rpc_clients[target] = client
config = Client(args.server, args.port_control, "master_config") master_management = Client(args.server, args.port_control, "master_management")
try: try:
server_name = config.get_name() server_name = master_management.get_name()
finally: finally:
config.close_rpc() master_management.close_rpc()
disconnect_reported = False disconnect_reported = False
def report_disconnect(): def report_disconnect():

View File

@ -65,14 +65,6 @@ def get_argparser():
return parser return parser
class MasterConfig:
def __init__(self, name):
self.name = name
def get_name(self):
return self.name
def main(): def main():
args = get_argparser().parse_args() args = get_argparser().parse_args()
log_forwarder = init_log(args) log_forwarder = init_log(args)
@ -118,8 +110,6 @@ def main():
scheduler.start(loop=loop) scheduler.start(loop=loop)
atexit_register_coroutine(scheduler.stop, loop=loop) atexit_register_coroutine(scheduler.stop, loop=loop)
config = MasterConfig(args.name)
worker_handlers.update({ worker_handlers.update({
"get_device_db": device_db.get_device_db, "get_device_db": device_db.get_device_db,
"get_device": device_db.get, "get_device": device_db.get,
@ -136,15 +126,17 @@ def main():
experiment_db.scan_repository_async(loop=loop) experiment_db.scan_repository_async(loop=loop)
signal_handler_task = loop.create_task(signal_handler.wait_terminate()) signal_handler_task = loop.create_task(signal_handler.wait_terminate())
master_terminate = SimpleNamespace(terminate=lambda: signal_handler_task.cancel()) master_management = SimpleNamespace(
get_name=lambda: args.name,
terminate=lambda: signal_handler_task.cancel()
)
server_control = RPCServer({ server_control = RPCServer({
"master_config": config, "master_management": master_management,
"master_device_db": device_db, "master_device_db": device_db,
"master_dataset_db": dataset_db, "master_dataset_db": dataset_db,
"master_schedule": scheduler, "master_schedule": scheduler,
"master_experiment_db": experiment_db, "master_experiment_db": experiment_db,
"master_terminate": master_terminate
}, allow_parallel=True) }, allow_parallel=True)
loop.run_until_complete(server_control.start( loop.run_until_complete(server_control.start(
bind, args.port_control)) bind, args.port_control))