From 7b3ba24beda011ecaaee5004ecd5f180889f89e2 Mon Sep 17 00:00:00 2001 From: Dmitri Gavrilov Date: Wed, 29 Dec 2021 09:58:02 -0500 Subject: [PATCH] ENH: renamed 'task_load_result' to 'task_result_get' --- bluesky_queueserver/manager/manager.py | 19 +++++++------ bluesky_queueserver/manager/qserver_cli.py | 4 +-- bluesky_queueserver/manager/tests/common.py | 2 +- .../manager/tests/test_qserver_cli.py | 10 +++---- .../manager/tests/test_zmq_api.py | 6 ++-- docs/source/re_manager_api.rst | 28 +++++++++---------- 6 files changed, 35 insertions(+), 34 deletions(-) diff --git a/bluesky_queueserver/manager/manager.py b/bluesky_queueserver/manager/manager.py index 7dbc29ef..76b09e64 100644 --- a/bluesky_queueserver/manager/manager.py +++ b/bluesky_queueserver/manager/manager.py @@ -2229,16 +2229,17 @@ async def _function_execute_handler(self, request): return {"success": success, "msg": msg, "item": item, "task_uid": task_uid} - async def _task_load_result_handler(self, request): + async def _task_result_get_handler(self, request): """ - Load result of a task executed by the worker process. The request must contain valid ``task_uid``. - Task UIDs are returned by the API used to start tasks. Returned parameters: ``success`` and - ``msg`` indicate success of the API call and error message in case of API call failure; - ``status`` is the status of the task (``running``, ``completed``, ``not_found``), ``result`` - is a dictionary with information about the task. The information is be different for - the completed and running tasks. If ``status=='not_found'``, then is ``result`` is ``{}``. + Returns the information of a task executed by the worker process. The request must contain + valid ``task_uid``, returned by one of APIs that starts tasks. Returned + parameters: ``success`` and ``msg`` indicate success of the API call and error message in + case of API call failure; ``status`` is the status of the task (``running``, ``completed``, + ``not_found``), ``result`` is a dictionary with information about the task. The information + is be different for the completed and running tasks. If ``status=='not_found'``, then is + ``result`` is ``{}``. """ - logger.debug("Load result of the task executed by RE worker ...") + logger.debug("Request for the result of the task executed by RE worker ...") task_uid = None @@ -2519,7 +2520,7 @@ async def _zmq_execute(self, msg): "environment_destroy": "_environment_destroy_handler", "script_upload": "_script_upload_handler", "function_execute": "_function_execute_handler", - "task_load_result": "_task_load_result_handler", + "task_result_get": "_task_result_get_handler", "queue_mode_set": "_queue_mode_set_handler", "queue_item_add": "_queue_item_add_handler", "queue_item_add_batch": "_queue_item_add_batch_handler", diff --git a/bluesky_queueserver/manager/qserver_cli.py b/bluesky_queueserver/manager/qserver_cli.py index 27f15ee5..98cdaf45 100644 --- a/bluesky_queueserver/manager/qserver_cli.py +++ b/bluesky_queueserver/manager/qserver_cli.py @@ -138,7 +138,7 @@ class QServerExitCodes(enum.Enum): qserver script upload background # ... in the background qserver script upload update-re # ... allow 'RE' and 'db' to be updated -qserver task load result # Load status or result of a task with the given UID +qserver task result get # Load status or result of a task with the given UID qserver manager stop # Safely exit RE Manager application qserver manager stop safe on # Safely exit RE Manager application @@ -861,7 +861,7 @@ def create_msg(params): elif command == "task": if len(params) != 3: raise CommandParameterError(f"Request '{command}' must include at 3 parameters") - if (params[0] == "load") and (params[1] == "result"): + if (params[0] == "result") and (params[1] == "get"): task_uid = str(params[2]) method = f"{command}_{params[0]}_{params[1]}" prms = {"task_uid": task_uid} diff --git a/bluesky_queueserver/manager/tests/common.py b/bluesky_queueserver/manager/tests/common.py index ac773a8d..5986272f 100644 --- a/bluesky_queueserver/manager/tests/common.py +++ b/bluesky_queueserver/manager/tests/common.py @@ -289,7 +289,7 @@ def wait_for_task_result(time, task_uid): while ttime.time() < time_stop: ttime.sleep(dt / 2) try: - resp, _ = zmq_secure_request("task_load_result", params={"task_uid": task_uid}) + resp, _ = zmq_secure_request("task_result_get", params={"task_uid": task_uid}) assert resp["success"] is True, f"Request for task result failed: {resp['msg']}" assert resp["task_uid"] == task_uid diff --git a/bluesky_queueserver/manager/tests/test_qserver_cli.py b/bluesky_queueserver/manager/tests/test_qserver_cli.py index 7b686576..e6cb0d63 100644 --- a/bluesky_queueserver/manager/tests/test_qserver_cli.py +++ b/bluesky_queueserver/manager/tests/test_qserver_cli.py @@ -1216,17 +1216,17 @@ def test_function_execute_2_fail(re_manager): # noqa: F811 assert subprocess.call(["qserver", "function", "execute", item, "invalid_param"]) == PARAM_ERROR -def test_task_load_result_1(re_manager): # noqa: F811 +def test_task_result_get_1(re_manager): # noqa: F811 """ - Tests for 'qserver task load result'. + Tests for 'qserver task result_get'. """ # The request should be successful for any 'task_uid'. task_uid = "01e80342-5e36-44de-bc86-9bd8d57c9885" - assert subprocess.call(["qserver", "task", "load", "result", task_uid]) == SUCCESS + assert subprocess.call(["qserver", "task", "result", "get", task_uid]) == SUCCESS # Some cases of invalid parameters - assert subprocess.call(["qserver", "task", "load", "result"]) == PARAM_ERROR - assert subprocess.call(["qserver", "task", "load", "something"]) == PARAM_ERROR + assert subprocess.call(["qserver", "task", "result", "get"]) == PARAM_ERROR + assert subprocess.call(["qserver", "task", "result", "something"]) == PARAM_ERROR assert subprocess.call(["qserver", "task", "something", "something"]) == PARAM_ERROR diff --git a/bluesky_queueserver/manager/tests/test_zmq_api.py b/bluesky_queueserver/manager/tests/test_zmq_api.py index a03b35d5..bd129108 100644 --- a/bluesky_queueserver/manager/tests/test_zmq_api.py +++ b/bluesky_queueserver/manager/tests/test_zmq_api.py @@ -1438,7 +1438,7 @@ def test_zmq_api_script_upload_1(re_manager, run_in_background): # noqa: F811 status, _ = zmq_single_request("status") assert status["worker_background_tasks"] == (1 if run_in_background else 0) - resp3, _ = zmq_single_request("task_load_result", params={"task_uid": task_uid}) + resp3, _ = zmq_single_request("task_result_get", params={"task_uid": task_uid}) assert resp3["success"] is True assert resp3["msg"] == "" assert resp3["task_uid"] == task_uid @@ -1463,7 +1463,7 @@ def test_zmq_api_script_upload_1(re_manager, run_in_background): # noqa: F811 assert status["items_in_history"] == 0 assert status["worker_background_tasks"] == 0 - resp4, _ = zmq_single_request("task_load_result", params={"task_uid": task_uid}) + resp4, _ = zmq_single_request("task_result_get", params={"task_uid": task_uid}) assert resp4["success"] is True assert resp4["msg"] == "" assert resp4["task_uid"] == task_uid @@ -2025,7 +2025,7 @@ def test_zmq_api_function_execute_1(re_manager, run_in_background, wait_for_idle # manager state to switch to idle. This only makes sense when function is # executed on the foreground. assert wait_for_condition(time=10, condition=condition_manager_idle) - resp2, _ = zmq_single_request("task_load_result", params={"task_uid": task_uid}) + resp2, _ = zmq_single_request("task_result_get", params={"task_uid": task_uid}) assert resp2["success"] is True, pprint.pformat(resp2) assert resp2["result"]["success"] is True, pprint.pformat(resp2["result"]) else: diff --git a/docs/source/re_manager_api.rst b/docs/source/re_manager_api.rst index 985750fd..b993902f 100644 --- a/docs/source/re_manager_api.rst +++ b/docs/source/re_manager_api.rst @@ -122,7 +122,7 @@ Run tasks in RE Worker namespace: - :ref:`method_script_upload` - :ref:`method_function_execute` -- :ref:`method_task_load_result` +- :ref:`method_task_result_get` Stopping RE Manager (mostly used in testing): @@ -192,7 +192,7 @@ Returns **msg**: *str* **task_results_uid**: *str* UID of the dictionary of task results. UID is updated each time results of a new completed tasks are added to the dictionary. Check the status of the pending tasks - (see *task_load_result* API) once UID is changed. + (see *task_result_get* API) once UID is changed. **plans_allowed_uid**: *str* UID for the list of allowed plans. UID is updated each time the contents of @@ -1339,7 +1339,7 @@ Description Upload and execute script in RE Worker namespace. The script may a objects defined in the namespace, including plans and devices. Dynamic modification of the worker namespace may be used to implement more flexible workflows. The API call updates the lists of existing and allowed plans and devices if necessary. Changes in - the lists will be indicated by changed list UIDs. Use *'task_load_result'* API to check + the lists will be indicated by changed list UIDs. Use *'task_result_get'* API to check if the script was loaded correctly. Note, that if the task fails, the script is still executed to the point where the exception is raised, changing the environment. ------------ ----------------------------------------------------------------------------------------- @@ -1371,10 +1371,10 @@ Returns **success**: *boolean* **task_uid**: *str* or *None* Task UID can be used to check status of the task and download results once the task - is completed (see *task_load_result* API). + is completed (see *task_result_get* API). ------------ ----------------------------------------------------------------------------------------- Execution The method initiates the operation. Monitor *task_results_uid* status field and call - *task_load_results* API to check for success. + *task_result_get* API to check for success. ============ ========================================================================================= @@ -1397,7 +1397,7 @@ Description Start execution of a function in RE Worker namespace. The function The method allows to pass parameters (*args* and *kwargs*) to the function. Once the task is completed, the results of the function execution, including the return value, can be - loaded using *task_load_result* method. If the task fails, the return value is a string + loaded using *task_result_get* method. If the task fails, the return value is a string with full traceback of the raised exception. The data types of parameters and return values must be JSON serializable. The task fails if the return value can not be serialized. @@ -1405,7 +1405,7 @@ Description Start execution of a function in RE Worker namespace. The function (*success=True*), the server starts the task, which attempts to execute the function with given name and parameters. The function may still fail start (e.g. if the user is permitted to execute function with the given name, but the function is not defined - in the namespace). Use *'task_load_result'* method with the returned *task_uid* to + in the namespace). Use *'task_result_get'* method with the returned *task_uid* to check the status of the taks and load the result upon completion. ------------ ----------------------------------------------------------------------------------------- Parameters **item**: *dict* @@ -1440,22 +1440,22 @@ Returns **success**: *boolean* **task_uid**: *str* or *None* Task UID can be used to check status of the task and download results once the task - is completed (see *task_load_result* API). *None* is returned if the request fails. + is completed (see *task_result_get* API). *None* is returned if the request fails. ------------ ----------------------------------------------------------------------------------------- Execution The method initiates the operation. Monitor *task_results_uid* status field and call - *task_load_results* API to check for success. + *task_result_get* API to check for success. ============ ========================================================================================= -.. _method_task_load_result: +.. _method_task_result_get: -**'task_load_result'** -^^^^^^^^^^^^^^^^^^^^^^ +**'task_result_get'** +^^^^^^^^^^^^^^^^^^^^^ ============ ========================================================================================= -Method **'task_load_result'** +Method **'task_result_get'** ------------ ----------------------------------------------------------------------------------------- -Description Load the status and results of task execution. The completed tasks are stored at +Description Get the status and results of task execution. The completed tasks are stored at the server at least for the period determined by retention time (currently 120 seconds after completion of the task). The expired results could be automatically deleted at any time and the method will return the task status as *'not_found'*.