Skip to content

Commit

Permalink
ENH: renamed 'task_load_result' to 'task_result_get'
Browse files Browse the repository at this point in the history
  • Loading branch information
dmgav committed Dec 29, 2021
1 parent eed1dc4 commit 7b3ba24
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 34 deletions.
19 changes: 10 additions & 9 deletions bluesky_queueserver/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions bluesky_queueserver/manager/qserver_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class QServerExitCodes(enum.Enum):
qserver script upload <path-to-file> background # ... in the background
qserver script upload <path-to-file> update-re # ... allow 'RE' and 'db' to be updated
qserver task load result <task-uid> # Load status or result of a task with the given UID
qserver task result get <task-uid> # 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
Expand Down Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion bluesky_queueserver/manager/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions bluesky_queueserver/manager/tests/test_qserver_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions bluesky_queueserver/manager/tests/test_zmq_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
28 changes: 14 additions & 14 deletions docs/source/re_manager_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
------------ -----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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.
============ =========================================================================================


Expand All @@ -1397,15 +1397,15 @@ 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.

The method only **initiates** execution of the function. If the request is successful
(*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*
Expand Down Expand Up @@ -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'*.
Expand Down

0 comments on commit 7b3ba24

Please sign in to comment.