Skip to content

Commit 47e6fe4

Browse files
add docstring and cmd_data check (#2782)
Co-authored-by: Yuan-Ting Hsieh (謝沅廷) <[email protected]>
1 parent 73b75c9 commit 47e6fe4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

nvflare/fuel/flare_api/flare_api.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,27 @@ def _collect_info(self, cmd: str, job_id: str, target_type: str, targets=None) -
802802
reply = self._do_command(command, enforce_meta=False)
803803
return self._get_dict_data(reply)
804804

805-
def do_app_command(self, job_id: str, topic: str, cmd_data):
805+
def do_app_command(self, job_id: str, topic: str, cmd_data) -> dict:
806+
"""Ask a running job to execute an app command
807+
808+
Args:
809+
job_id: the ID of the running job
810+
topic: topic of the command
811+
cmd_data: the data of the command. Must be JSON serializable.
812+
813+
Returns: result of the app command
814+
815+
If the job is not currently running, an exception will occur. User must make sure that the job is running when
816+
calling this method.
817+
818+
"""
806819
command = f"{AdminCommandNames.APP_COMMAND} {job_id} {topic}"
820+
if cmd_data:
821+
# cmd_data must be JSON serializable!
822+
try:
823+
json.dumps(cmd_data)
824+
except Exception as ex:
825+
raise ValueError(f"cmd_data cannot be JSON serialized: {ex}")
807826
reply = self._do_command(command, enforce_meta=False, props=cmd_data)
808827
return self._get_dict_data(reply)
809828

0 commit comments

Comments
 (0)