Prepare feature of running subtask (lpmn) within worker
There is sometimes a need for calling a subtask (lpmn task) from a worker. Prepare a class (within its own file) that will be accessible through nlp_ws library. The class should looks something like that (all of the function are debatable:
class Task(object):
def __init__(self, input_path: str, lpmn: str):
"""Constructor."""
pass
def run(self, blocking=True: bool, timeout=0: float, verbose=false: bool) -> None:
"""Run task.
Args:
blocking (bool): If the call of this function should be blocking.
timeout (float): Timeout used if blocking=True.
Pass '0' if the function should wait until the task is
finished or error occurred (raise an exception).
verbose (bool): Print progress or not.
"""
pass
def _wait(self, timeout) -> None:
"""Waits till the task is finished."""
def get_progress(self) -> float:
"""Returns progress of the running task.
Returns:
float. A progress (value between 0 and 1).
"""
pass
def get_output_path(self) -> str:
"""Returns path to the output (result of completed task).
The function waits if its needed.
"""
Using it code:
t = Task("requests/any2txt/241djh12312-d1", "wcrft2({'i-do-not': 'remember-options'})")
t.run() # task is running
# some operations
result = t.get_output_path()
Mind that the communication between lpmn_server and the application should be via RabbitMQ. For more information contact @tomekw