From 98cc05fe68fea8b65c888b07abd9eaec999f12d4 Mon Sep 17 00:00:00 2001 From: Jonatan Martens Date: Tue, 29 Sep 2020 11:34:54 +0300 Subject: [PATCH 1/9] [ADDED] full task api through decorator. [ADDED] dynamic variables_to_fetch through co_varnames --- pyzeebe/worker/task_handler.py | 24 +++++++++++++++------- pyzeebe/worker/task_router.py | 28 +++++++++++++++++++------- pyzeebe/worker/worker.py | 29 +++++++++++++++++++-------- tests/unit/worker/task_router_test.py | 26 ++++++++++++++++++++++++ tests/unit/worker/worker_test.py | 8 +++++++- 5 files changed, 92 insertions(+), 23 deletions(-) diff --git a/pyzeebe/worker/task_handler.py b/pyzeebe/worker/task_handler.py index 32abf090..a9ec89ba 100644 --- a/pyzeebe/worker/task_handler.py +++ b/pyzeebe/worker/task_handler.py @@ -26,8 +26,9 @@ def __init__(self, before: List[TaskDecorator] = None, after: List[TaskDecorator self.tasks: List[Task] = [] def task(self, task_type: str, exception_handler: ExceptionHandler = default_exception_handler, + variables_to_fetch: List[str] = None, timeout: int = 10000, max_jobs_to_activate: int = 32, before: List[TaskDecorator] = None, after: List[TaskDecorator] = None, single_value: bool = False, - variable_name: str = None): + variable_name: str = None, ): """Decorator to create a task single_value (bool): If the function returns a single value (int, string, list) and not a dictionary set this to True. @@ -38,21 +39,26 @@ def task(self, task_type: str, exception_handler: ExceptionHandler = default_exc raise NoVariableNameGiven(task_type=task_type) elif single_value and variable_name: - return self._non_dict_task(task_type=task_type, variable_name=variable_name, - exception_handler=exception_handler, before=before, after=after) + return self._non_dict_task(task_type=task_type, variable_name=variable_name, timeout=timeout, + max_jobs_to_activate=max_jobs_to_activate, exception_handler=exception_handler, + before=before, after=after, variables_to_fetch=variables_to_fetch) else: - return self._dict_task(task_type=task_type, exception_handler=exception_handler, before=before, after=after) + return self._dict_task(task_type=task_type, exception_handler=exception_handler, before=before, after=after, + timeout=timeout, max_jobs_to_activate=max_jobs_to_activate, + variables_to_fetch=variables_to_fetch) @abstractmethod def _dict_task(self, task_type: str, exception_handler: ExceptionHandler = default_exception_handler, - before: List[TaskDecorator] = None, after: List[TaskDecorator] = None): + timeout: int = 10000, max_jobs_to_activate: int = 32, before: List[TaskDecorator] = None, + after: List[TaskDecorator] = None, variables_to_fetch: List[str] = None): raise NotImplemented() @abstractmethod def _non_dict_task(self, task_type: str, variable_name: str, - exception_handler: ExceptionHandler = default_exception_handler, - before: List[TaskDecorator] = None, after: List[TaskDecorator] = None): + exception_handler: ExceptionHandler = default_exception_handler, timeout: int = 10000, + max_jobs_to_activate: int = 32, before: List[TaskDecorator] = None, + after: List[TaskDecorator] = None, variables_to_fetch: List[str] = None): raise NotImplemented() @staticmethod @@ -62,6 +68,10 @@ def inner_fn(*args, **kwargs): return inner_fn + @staticmethod + def get_variables_to_fetch_from_function(fn: Callable) -> List[str]: + return list(fn.__code__.co_varnames) + def remove_task(self, task_type: str) -> Task: task_index = self._get_task_index(task_type) return self.tasks.pop(task_index) diff --git a/pyzeebe/worker/task_router.py b/pyzeebe/worker/task_router.py index b049e2be..db504075 100644 --- a/pyzeebe/worker/task_router.py +++ b/pyzeebe/worker/task_router.py @@ -8,10 +8,16 @@ class ZeebeTaskRouter(ZeebeTaskHandler): def _dict_task(self, task_type: str, exception_handler: ExceptionHandler = default_exception_handler, - before: List[TaskDecorator] = None, after: List[TaskDecorator] = None): + timeout: int = 10000, max_jobs_to_activate: int = 32, before: List[TaskDecorator] = None, + after: List[TaskDecorator] = None, variables_to_fetch: List[str] = None): def wrapper(fn: Callable[..., Dict]): + nonlocal variables_to_fetch + if not variables_to_fetch: + variables_to_fetch = self.get_variables_to_fetch_from_function(fn) + task = self._create_task(task_type=task_type, task_handler=fn, exception_handler=exception_handler, - before=before, after=after) + timeout=timeout, max_jobs_to_activate=max_jobs_to_activate, before=before, + after=after, variables_to_fetch=variables_to_fetch) self.tasks.append(task) return fn @@ -19,13 +25,19 @@ def wrapper(fn: Callable[..., Dict]): return wrapper def _non_dict_task(self, task_type: str, variable_name: str, - exception_handler: ExceptionHandler = default_exception_handler, - before: List[TaskDecorator] = None, after: List[TaskDecorator] = None): + exception_handler: ExceptionHandler = default_exception_handler, timeout: int = 10000, + max_jobs_to_activate: int = 32, before: List[TaskDecorator] = None, + after: List[TaskDecorator] = None, variables_to_fetch: List[str] = None): def wrapper(fn: Callable[..., Dict]): + nonlocal variables_to_fetch + if not variables_to_fetch: + variables_to_fetch = self.get_variables_to_fetch_from_function(fn) + dict_fn = self._single_value_function_to_dict(variable_name=variable_name, fn=fn) task = self._create_task(task_type=task_type, task_handler=dict_fn, exception_handler=exception_handler, - before=before, after=after) + timeout=timeout, max_jobs_to_activate=max_jobs_to_activate, before=before, + after=after, variables_to_fetch=variables_to_fetch) self.tasks.append(task) return fn @@ -33,8 +45,10 @@ def wrapper(fn: Callable[..., Dict]): return wrapper def _create_task(self, task_type: str, task_handler: Callable, exception_handler: ExceptionHandler, - before: List[TaskDecorator] = None, after: List[TaskDecorator] = None) -> Task: - task = Task(task_type=task_type, task_handler=task_handler, exception_handler=exception_handler) + timeout: int = 10000, max_jobs_to_activate: int = 32, before: List[TaskDecorator] = None, + after: List[TaskDecorator] = None, variables_to_fetch: List[str] = None) -> Task: + task = Task(task_type=task_type, task_handler=task_handler, exception_handler=exception_handler, + timeout=timeout, max_jobs_to_activate=max_jobs_to_activate, variables_to_fetch=variables_to_fetch) return self._add_decorators_to_task(task, before or [], after or []) def _add_decorators_to_task(self, task: Task, before: List[TaskDecorator], diff --git a/pyzeebe/worker/worker.py b/pyzeebe/worker/worker.py index b5796270..9c47c47a 100644 --- a/pyzeebe/worker/worker.py +++ b/pyzeebe/worker/worker.py @@ -73,23 +73,35 @@ def _get_jobs(self, task: Task) -> Generator[Job, None, None]: request_timeout=self.request_timeout) def _dict_task(self, task_type: str, exception_handler: ExceptionHandler = default_exception_handler, - before: List[TaskDecorator] = None, after: List[TaskDecorator] = None): + timeout: int = 10000, max_jobs_to_activate: int = 32, before: List[TaskDecorator] = None, + after: List[TaskDecorator] = None, variables_to_fetch: List[str] = None): def wrapper(fn: Callable[..., Dict]): - task = Task(task_type=task_type, task_handler=fn, exception_handler=exception_handler, before=before, - after=after) + nonlocal variables_to_fetch + if not variables_to_fetch: + variables_to_fetch = self.get_variables_to_fetch_from_function(fn) + + task = Task(task_type=task_type, task_handler=fn, exception_handler=exception_handler, timeout=timeout, + max_jobs_to_activate=max_jobs_to_activate, before=before, after=after, + variables_to_fetch=variables_to_fetch) self._add_task(task) return fn return wrapper def _non_dict_task(self, task_type: str, variable_name: str, - exception_handler: ExceptionHandler = default_exception_handler, - before: List[TaskDecorator] = None, after: List[TaskDecorator] = None): + exception_handler: ExceptionHandler = default_exception_handler, timeout: int = 10000, + max_jobs_to_activate: int = 32, before: List[TaskDecorator] = None, + after: List[TaskDecorator] = None, variables_to_fetch: List[str] = None): def wrapper(fn: Callable[..., Dict]): + nonlocal variables_to_fetch + if not variables_to_fetch: + variables_to_fetch = self.get_variables_to_fetch_from_function(fn) + dict_fn = self._single_value_function_to_dict(variable_name=variable_name, fn=fn) - task = Task(task_type=task_type, task_handler=dict_fn, exception_handler=exception_handler, before=before, - after=after) + task = Task(task_type=task_type, task_handler=dict_fn, exception_handler=exception_handler, timeout=timeout, + max_jobs_to_activate=max_jobs_to_activate, before=before, after=after, + variables_to_fetch=variables_to_fetch) self._add_task(task) return fn @@ -114,7 +126,8 @@ def task_handler(job: Job) -> Job: return task_handler - def _run_task_inner_function(self, task: Task, job: Job) -> Tuple[Job, bool]: + @staticmethod + def _run_task_inner_function(task: Task, job: Job) -> Tuple[Job, bool]: task_succeeded = False try: job.variables = task.inner_function(**job.variables) diff --git a/tests/unit/worker/task_router_test.py b/tests/unit/worker/task_router_test.py index 5aaed427..d248367f 100644 --- a/tests/unit/worker/task_router_test.py +++ b/tests/unit/worker/task_router_test.py @@ -1,3 +1,4 @@ +from random import randint from unittest.mock import patch from uuid import uuid4 @@ -22,6 +23,31 @@ def run_around_tests(): zeebe_task_router = ZeebeTaskRouter() +def test_add_task_through_decorator(): + task_type = str(uuid4()) + timeout = randint(0, 10000) + max_jobs_to_activate = randint(0, 1000) + + @zeebe_task_router.task(task_type=task_type, timeout=timeout, max_jobs_to_activate=max_jobs_to_activate) + def example_test_task(x): + return {"x": x} + + assert len(zeebe_task_router.tasks) == 1 + + variable = str(uuid4()) + assert example_test_task(variable) == {"x": variable} + + global task + task = zeebe_task_router.get_task(task_type) + assert task is not None + + variable = str(uuid4()) + assert task.inner_function(variable) == {"x": variable} + assert task.variables_to_fetch == ["x"] + assert task.timeout == timeout + assert task.max_jobs_to_activate == max_jobs_to_activate + + def test_router_before_decorator(): task_type = str(uuid4()) zeebe_task_router.before(decorator) diff --git a/tests/unit/worker/worker_test.py b/tests/unit/worker/worker_test.py index bdef183a..64cd6505 100644 --- a/tests/unit/worker/worker_test.py +++ b/tests/unit/worker/worker_test.py @@ -1,3 +1,4 @@ +from random import randint from threading import Thread from unittest.mock import patch, MagicMock from uuid import uuid4 @@ -29,8 +30,10 @@ def run_around_tests(): def test_add_task_through_decorator(): task_type = str(uuid4()) + timeout = randint(0, 10000) + max_jobs_to_activate = randint(0, 1000) - @zeebe_worker.task(task_type=task_type) + @zeebe_worker.task(task_type=task_type, timeout=timeout, max_jobs_to_activate=max_jobs_to_activate) def example_test_task(x): return {"x": x} @@ -46,6 +49,9 @@ def example_test_task(x): variable = str(uuid4()) assert task.inner_function(variable) == {"x": variable} + assert task.variables_to_fetch == ["x"] + assert task.timeout == timeout + assert task.max_jobs_to_activate == max_jobs_to_activate assert callable(task.handler) job = random_job(task=task) From 288c22990cf64aaa5f672067677503c56cb1c3b7 Mon Sep 17 00:00:00 2001 From: Jonatan Martens Date: Tue, 29 Sep 2020 11:39:41 +0300 Subject: [PATCH 2/9] [CHANGED] Version to v2.1.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4230e5a9..ad32d26a 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pyzeebe", - version="2.0.1", + version="2.1.0", author="Jonatan Martens", author_email="jonatanmartenstav@gmail.com", description="Zeebe client api", From 50956c89512f586dbc6e89a01a47643efb279bab Mon Sep 17 00:00:00 2001 From: Jonatan Martens Date: Tue, 29 Sep 2020 11:40:52 +0300 Subject: [PATCH 3/9] [REMOVED] unnecessary comma --- pyzeebe/worker/task_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyzeebe/worker/task_handler.py b/pyzeebe/worker/task_handler.py index a9ec89ba..696f3f19 100644 --- a/pyzeebe/worker/task_handler.py +++ b/pyzeebe/worker/task_handler.py @@ -28,7 +28,7 @@ def __init__(self, before: List[TaskDecorator] = None, after: List[TaskDecorator def task(self, task_type: str, exception_handler: ExceptionHandler = default_exception_handler, variables_to_fetch: List[str] = None, timeout: int = 10000, max_jobs_to_activate: int = 32, before: List[TaskDecorator] = None, after: List[TaskDecorator] = None, single_value: bool = False, - variable_name: str = None, ): + variable_name: str = None): """Decorator to create a task single_value (bool): If the function returns a single value (int, string, list) and not a dictionary set this to True. From 90b75f994e099756dbb1a0958f0a8b5b8c9ef133 Mon Sep 17 00:00:00 2001 From: Jonatan Martens Date: Tue, 29 Sep 2020 11:42:51 +0300 Subject: [PATCH 4/9] [FIXED] JobStatus not exported --- pyzeebe/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyzeebe/__init__.py b/pyzeebe/__init__.py index 2fbae03c..409c1d8c 100644 --- a/pyzeebe/__init__.py +++ b/pyzeebe/__init__.py @@ -3,6 +3,7 @@ from pyzeebe.credentials.camunda_cloud_credentials import CamundaCloudCredentials from pyzeebe.credentials.oauth_credentials import OAuthCredentials from pyzeebe.job.job import Job +from pyzeebe.job.job_status import JobStatus from pyzeebe.task.exception_handler import ExceptionHandler from pyzeebe.task.task_decorator import TaskDecorator from pyzeebe.worker.task_router import ZeebeTaskRouter From 76b55eb83ebe60d42dfe458b3c94d0da3c080468 Mon Sep 17 00:00:00 2001 From: Jonatan Martens Date: Tue, 29 Sep 2020 11:56:35 +0300 Subject: [PATCH 5/9] [FIXED] Exceptions not exported --- pyzeebe/__init__.py | 2 +- pyzeebe/common/__init__.py | 0 pyzeebe/common/exceptions.py | 87 ------------------- pyzeebe/exceptions/__init__.py | 3 + pyzeebe/exceptions/job_exceptions.py | 28 ++++++ pyzeebe/exceptions/message_exceptions.py | 5 ++ pyzeebe/exceptions/pyzeebe_exceptions.py | 16 ++++ pyzeebe/exceptions/workflow_exceptions.py | 29 +++++++ pyzeebe/exceptions/zeebe_exceptions.py | 13 +++ pyzeebe/grpc_internals/zeebe_adapter_base.py | 2 +- pyzeebe/grpc_internals/zeebe_job_adapter.py | 2 +- .../grpc_internals/zeebe_message_adapter.py | 2 +- .../grpc_internals/zeebe_workflow_adapter.py | 4 +- pyzeebe/job/job.py | 2 +- pyzeebe/worker/task_handler.py | 3 +- tests/integration/integration_test.py | 5 +- tests/unit/client/client_test.py | 2 +- .../grpc_internals/zeebe_adapter_base_test.py | 2 +- .../grpc_internals/zeebe_job_adapter_test.py | 2 +- .../zeebe_message_adapter_test.py | 2 +- .../zeebe_workflow_adapter_test.py | 3 +- tests/unit/job/job_test.py | 2 +- tests/unit/worker/task_handler_test.py | 3 +- 23 files changed, 115 insertions(+), 104 deletions(-) delete mode 100644 pyzeebe/common/__init__.py delete mode 100644 pyzeebe/common/exceptions.py create mode 100644 pyzeebe/exceptions/__init__.py create mode 100644 pyzeebe/exceptions/job_exceptions.py create mode 100644 pyzeebe/exceptions/message_exceptions.py create mode 100644 pyzeebe/exceptions/pyzeebe_exceptions.py create mode 100644 pyzeebe/exceptions/workflow_exceptions.py create mode 100644 pyzeebe/exceptions/zeebe_exceptions.py diff --git a/pyzeebe/__init__.py b/pyzeebe/__init__.py index 409c1d8c..be126098 100644 --- a/pyzeebe/__init__.py +++ b/pyzeebe/__init__.py @@ -1,5 +1,5 @@ +from pyzeebe import exceptions from pyzeebe.client.client import ZeebeClient -from pyzeebe.common import exceptions from pyzeebe.credentials.camunda_cloud_credentials import CamundaCloudCredentials from pyzeebe.credentials.oauth_credentials import OAuthCredentials from pyzeebe.job.job import Job diff --git a/pyzeebe/common/__init__.py b/pyzeebe/common/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/pyzeebe/common/exceptions.py b/pyzeebe/common/exceptions.py deleted file mode 100644 index 1dc1287a..00000000 --- a/pyzeebe/common/exceptions.py +++ /dev/null @@ -1,87 +0,0 @@ -class TaskNotFound(Exception): - pass - - -class WorkflowNotFound(Exception): - def __init__(self, bpmn_process_id: str, version: int): - super().__init__( - f"Workflow definition: {bpmn_process_id} with {version} was not found") - self.bpmn_process_id = bpmn_process_id - self.version = version - - -class WorkflowInstanceNotFound(Exception): - def __init__(self, workflow_instance_key: int): - super().__init__(f"Workflow instance key: {workflow_instance_key} was not found") - self.workflow_instance_key = workflow_instance_key - - -class WorkflowHasNoStartEvent(Exception): - def __init__(self, bpmn_process_id: str): - super().__init__(f"Workflow {bpmn_process_id} has no start event that can be called manually") - self.bpmn_process_id = bpmn_process_id - - -class ActivateJobsRequestInvalid(Exception): - def __init__(self, task_type: str, worker: str, timeout: int, max_jobs_to_activate: int): - msg = "Failed to activate jobs. Reasons:" - if task_type == "" or task_type is None: - msg = msg + "task_type is empty, " - if worker == "" or task_type is None: - msg = msg + "worker is empty, " - if timeout < 1: - msg = msg + "job timeout is smaller than 0ms, " - if max_jobs_to_activate < 1: - msg = msg + "max_jobs_to_activate is smaller than 0ms, " - - super().__init__(msg) - - -class JobAlreadyDeactivated(Exception): - def __init__(self, job_key: int): - super().__init__(f"Job {job_key} was already stopped (Completed/Failed/Error)") - self.job_key = job_key - - -class JobNotFound(Exception): - def __init__(self, job_key: int): - super().__init__(f"Job {job_key} not found") - self.job_key = job_key - - -class WorkflowInvalid(Exception): - pass - - -class MessageAlreadyExists(Exception): - pass - - -class ElementNotFound(Exception): - pass - - -class InvalidJSON(Exception): - pass - - -class ZeebeBackPressure(Exception): - pass - - -class ZeebeGatewayUnavailable(Exception): - pass - - -class ZeebeInternalError(Exception): - pass - - -class NoVariableNameGiven(Exception): - def __init__(self, task_type: str): - super().__init__(f"No variable name given for single_value task {task_type}") - self.task_type = task_type - - -class NoZeebeAdapter(Exception): - pass diff --git a/pyzeebe/exceptions/__init__.py b/pyzeebe/exceptions/__init__.py new file mode 100644 index 00000000..6fa8e9b7 --- /dev/null +++ b/pyzeebe/exceptions/__init__.py @@ -0,0 +1,3 @@ +from .job_exceptions import * +from .pyzeebe_exceptions import * +from .workflow_exceptions import * diff --git a/pyzeebe/exceptions/job_exceptions.py b/pyzeebe/exceptions/job_exceptions.py new file mode 100644 index 00000000..feb27a42 --- /dev/null +++ b/pyzeebe/exceptions/job_exceptions.py @@ -0,0 +1,28 @@ +from pyzeebe.exceptions.pyzeebe_exceptions import PyZeebeException + + +class ActivateJobsRequestInvalid(PyZeebeException): + def __init__(self, task_type: str, worker: str, timeout: int, max_jobs_to_activate: int): + msg = "Failed to activate jobs. Reasons:" + if task_type == "" or task_type is None: + msg = msg + "task_type is empty, " + if worker == "" or task_type is None: + msg = msg + "worker is empty, " + if timeout < 1: + msg = msg + "job timeout is smaller than 0ms, " + if max_jobs_to_activate < 1: + msg = msg + "max_jobs_to_activate is smaller than 0ms, " + + super().__init__(msg) + + +class JobAlreadyDeactivated(PyZeebeException): + def __init__(self, job_key: int): + super().__init__(f"Job {job_key} was already stopped (Completed/Failed/Error)") + self.job_key = job_key + + +class JobNotFound(PyZeebeException): + def __init__(self, job_key: int): + super().__init__(f"Job {job_key} not found") + self.job_key = job_key diff --git a/pyzeebe/exceptions/message_exceptions.py b/pyzeebe/exceptions/message_exceptions.py new file mode 100644 index 00000000..d93c5068 --- /dev/null +++ b/pyzeebe/exceptions/message_exceptions.py @@ -0,0 +1,5 @@ +from pyzeebe.exceptions.pyzeebe_exceptions import PyZeebeException + + +class MessageAlreadyExists(PyZeebeException): + pass diff --git a/pyzeebe/exceptions/pyzeebe_exceptions.py b/pyzeebe/exceptions/pyzeebe_exceptions.py new file mode 100644 index 00000000..9ac453a6 --- /dev/null +++ b/pyzeebe/exceptions/pyzeebe_exceptions.py @@ -0,0 +1,16 @@ +class PyZeebeException(Exception): + pass + + +class TaskNotFound(PyZeebeException): + pass + + +class NoVariableNameGiven(PyZeebeException): + def __init__(self, task_type: str): + super().__init__(f"No variable name given for single_value task {task_type}") + self.task_type = task_type + + +class NoZeebeAdapter(PyZeebeException): + pass diff --git a/pyzeebe/exceptions/workflow_exceptions.py b/pyzeebe/exceptions/workflow_exceptions.py new file mode 100644 index 00000000..688e6cfd --- /dev/null +++ b/pyzeebe/exceptions/workflow_exceptions.py @@ -0,0 +1,29 @@ +from pyzeebe.exceptions.pyzeebe_exceptions import PyZeebeException + + +class WorkflowNotFound(PyZeebeException): + def __init__(self, bpmn_process_id: str, version: int): + super().__init__( + f"Workflow definition: {bpmn_process_id} with {version} was not found") + self.bpmn_process_id = bpmn_process_id + self.version = version + + +class WorkflowInstanceNotFound(PyZeebeException): + def __init__(self, workflow_instance_key: int): + super().__init__(f"Workflow instance key: {workflow_instance_key} was not found") + self.workflow_instance_key = workflow_instance_key + + +class WorkflowHasNoStartEvent(PyZeebeException): + def __init__(self, bpmn_process_id: str): + super().__init__(f"Workflow {bpmn_process_id} has no start event that can be called manually") + self.bpmn_process_id = bpmn_process_id + + +class WorkflowInvalid(PyZeebeException): + pass + + +class InvalidJSON(PyZeebeException): + pass diff --git a/pyzeebe/exceptions/zeebe_exceptions.py b/pyzeebe/exceptions/zeebe_exceptions.py new file mode 100644 index 00000000..7fe37a3d --- /dev/null +++ b/pyzeebe/exceptions/zeebe_exceptions.py @@ -0,0 +1,13 @@ +from pyzeebe.exceptions.pyzeebe_exceptions import PyZeebeException + + +class ZeebeBackPressure(PyZeebeException): + pass + + +class ZeebeGatewayUnavailable(PyZeebeException): + pass + + +class ZeebeInternalError(PyZeebeException): + pass diff --git a/pyzeebe/grpc_internals/zeebe_adapter_base.py b/pyzeebe/grpc_internals/zeebe_adapter_base.py index b0b0623e..396ddcfa 100644 --- a/pyzeebe/grpc_internals/zeebe_adapter_base.py +++ b/pyzeebe/grpc_internals/zeebe_adapter_base.py @@ -3,8 +3,8 @@ import grpc -from pyzeebe.common.exceptions import ZeebeInternalError, ZeebeBackPressure, ZeebeGatewayUnavailable from pyzeebe.credentials.base_credentials import BaseCredentials +from pyzeebe.exceptions.zeebe_exceptions import ZeebeBackPressure, ZeebeGatewayUnavailable, ZeebeInternalError from pyzeebe.grpc_internals.zeebe_pb2_grpc import GatewayStub diff --git a/pyzeebe/grpc_internals/zeebe_job_adapter.py b/pyzeebe/grpc_internals/zeebe_job_adapter.py index eb0aaa5d..3eb739b3 100644 --- a/pyzeebe/grpc_internals/zeebe_job_adapter.py +++ b/pyzeebe/grpc_internals/zeebe_job_adapter.py @@ -4,7 +4,7 @@ import grpc -from pyzeebe.common.exceptions import JobNotFound, JobAlreadyDeactivated, ActivateJobsRequestInvalid +from pyzeebe.exceptions import ActivateJobsRequestInvalid, JobAlreadyDeactivated, JobNotFound from pyzeebe.grpc_internals.zeebe_adapter_base import ZeebeAdapterBase from pyzeebe.grpc_internals.zeebe_pb2 import (ActivateJobsRequest, CompleteJobRequest, CompleteJobResponse, FailJobRequest, FailJobResponse, ThrowErrorRequest, diff --git a/pyzeebe/grpc_internals/zeebe_message_adapter.py b/pyzeebe/grpc_internals/zeebe_message_adapter.py index 1b41a6c8..cdb6cc68 100644 --- a/pyzeebe/grpc_internals/zeebe_message_adapter.py +++ b/pyzeebe/grpc_internals/zeebe_message_adapter.py @@ -3,7 +3,7 @@ import grpc -from pyzeebe.common.exceptions import MessageAlreadyExists +from pyzeebe.exceptions.message_exceptions import MessageAlreadyExists from pyzeebe.grpc_internals.zeebe_adapter_base import ZeebeAdapterBase from pyzeebe.grpc_internals.zeebe_pb2 import PublishMessageRequest, PublishMessageResponse diff --git a/pyzeebe/grpc_internals/zeebe_workflow_adapter.py b/pyzeebe/grpc_internals/zeebe_workflow_adapter.py index a41105a5..28129688 100644 --- a/pyzeebe/grpc_internals/zeebe_workflow_adapter.py +++ b/pyzeebe/grpc_internals/zeebe_workflow_adapter.py @@ -4,8 +4,8 @@ import grpc -from pyzeebe.common.exceptions import (WorkflowNotFound, WorkflowInstanceNotFound, WorkflowInvalid, - WorkflowHasNoStartEvent, InvalidJSON) +from pyzeebe.exceptions import InvalidJSON, WorkflowNotFound, WorkflowInstanceNotFound, WorkflowHasNoStartEvent, \ + WorkflowInvalid from pyzeebe.grpc_internals.zeebe_adapter_base import ZeebeAdapterBase from pyzeebe.grpc_internals.zeebe_pb2 import (CreateWorkflowInstanceRequest, CreateWorkflowInstanceWithResultRequest, CancelWorkflowInstanceRequest, WorkflowRequestObject, diff --git a/pyzeebe/job/job.py b/pyzeebe/job/job.py index f522ab0d..9eb3e6e0 100644 --- a/pyzeebe/job/job.py +++ b/pyzeebe/job/job.py @@ -1,6 +1,6 @@ from typing import Dict -from pyzeebe.common.exceptions import NoZeebeAdapter +from pyzeebe.exceptions import NoZeebeAdapter from pyzeebe.job.job_status import JobStatus diff --git a/pyzeebe/worker/task_handler.py b/pyzeebe/worker/task_handler.py index 696f3f19..b9d3ab37 100644 --- a/pyzeebe/worker/task_handler.py +++ b/pyzeebe/worker/task_handler.py @@ -2,8 +2,9 @@ from abc import abstractmethod from typing import Tuple, List, Callable -from pyzeebe.common.exceptions import TaskNotFound, NoVariableNameGiven from pyzeebe.decorators.zeebe_decorator_base import ZeebeDecoratorBase +from pyzeebe.exceptions import NoVariableNameGiven +from pyzeebe.exceptions.pyzeebe_exceptions import TaskNotFound from pyzeebe.job.job import Job from pyzeebe.task.exception_handler import ExceptionHandler from pyzeebe.task.task import Task diff --git a/tests/integration/integration_test.py b/tests/integration/integration_test.py index 319a656c..f9897f5c 100644 --- a/tests/integration/integration_test.py +++ b/tests/integration/integration_test.py @@ -5,7 +5,8 @@ import pytest -from pyzeebe import ZeebeWorker, ZeebeClient, exceptions, Job +import pyzeebe.exceptions.workflow_exceptions +from pyzeebe import ZeebeWorker, ZeebeClient, Job zeebe_client: ZeebeClient zeebe_worker = ZeebeWorker() @@ -48,7 +49,7 @@ def test_run_workflow(): def test_non_existent_workflow(): - with pytest.raises(exceptions.WorkflowNotFound): + with pytest.raises(pyzeebe.exceptions.workflow_exceptions.WorkflowNotFound): zeebe_client.run_workflow(str(uuid4())) diff --git a/tests/unit/client/client_test.py b/tests/unit/client/client_test.py index 92bdf65d..3ec19f5b 100644 --- a/tests/unit/client/client_test.py +++ b/tests/unit/client/client_test.py @@ -3,7 +3,7 @@ from uuid import uuid4 from pyzeebe.client.client import ZeebeClient -from pyzeebe.common.exceptions import WorkflowNotFound +from pyzeebe.exceptions import WorkflowNotFound from tests.unit.utils.grpc_utils import * zeebe_client: ZeebeClient diff --git a/tests/unit/grpc_internals/zeebe_adapter_base_test.py b/tests/unit/grpc_internals/zeebe_adapter_base_test.py index 55388f9b..1c96929f 100644 --- a/tests/unit/grpc_internals/zeebe_adapter_base_test.py +++ b/tests/unit/grpc_internals/zeebe_adapter_base_test.py @@ -2,9 +2,9 @@ from unittest.mock import patch from uuid import uuid4 -from pyzeebe.common.exceptions import * from pyzeebe.credentials.camunda_cloud_credentials import CamundaCloudCredentials from pyzeebe.credentials.oauth_credentials import OAuthCredentials +from pyzeebe.exceptions.zeebe_exceptions import ZeebeBackPressure, ZeebeGatewayUnavailable, ZeebeInternalError from pyzeebe.grpc_internals.zeebe_adapter_base import ZeebeAdapterBase from tests.unit.utils.grpc_utils import * from tests.unit.utils.random_utils import RANDOM_RANGE diff --git a/tests/unit/grpc_internals/zeebe_job_adapter_test.py b/tests/unit/grpc_internals/zeebe_job_adapter_test.py index 9fa73940..7de0a0cd 100644 --- a/tests/unit/grpc_internals/zeebe_job_adapter_test.py +++ b/tests/unit/grpc_internals/zeebe_job_adapter_test.py @@ -2,7 +2,7 @@ from unittest.mock import MagicMock from uuid import uuid4 -from pyzeebe.common.exceptions import * +from pyzeebe.exceptions import ActivateJobsRequestInvalid, JobAlreadyDeactivated, JobNotFound from pyzeebe.grpc_internals.zeebe_job_adapter import ZeebeJobAdapter from pyzeebe.grpc_internals.zeebe_pb2 import * from pyzeebe.job.job import Job diff --git a/tests/unit/grpc_internals/zeebe_message_adapter_test.py b/tests/unit/grpc_internals/zeebe_message_adapter_test.py index e773748e..bf84eda7 100644 --- a/tests/unit/grpc_internals/zeebe_message_adapter_test.py +++ b/tests/unit/grpc_internals/zeebe_message_adapter_test.py @@ -2,7 +2,7 @@ from unittest.mock import MagicMock from uuid import uuid4 -from pyzeebe.common.exceptions import MessageAlreadyExists +from pyzeebe.exceptions.message_exceptions import MessageAlreadyExists from pyzeebe.grpc_internals.zeebe_message_adapter import ZeebeMessageAdapter from pyzeebe.grpc_internals.zeebe_pb2 import * from tests.unit.utils.grpc_utils import * diff --git a/tests/unit/grpc_internals/zeebe_workflow_adapter_test.py b/tests/unit/grpc_internals/zeebe_workflow_adapter_test.py index 92de9ef7..46bd9af7 100644 --- a/tests/unit/grpc_internals/zeebe_workflow_adapter_test.py +++ b/tests/unit/grpc_internals/zeebe_workflow_adapter_test.py @@ -3,7 +3,8 @@ from unittest.mock import patch, MagicMock from uuid import uuid4 -from pyzeebe.common.exceptions import * +from pyzeebe.exceptions import InvalidJSON, WorkflowNotFound, WorkflowInstanceNotFound, WorkflowHasNoStartEvent, \ + WorkflowInvalid from pyzeebe.grpc_internals.zeebe_workflow_adapter import ZeebeWorkflowAdapter from tests.unit.utils.grpc_utils import * from tests.unit.utils.random_utils import RANDOM_RANGE diff --git a/tests/unit/job/job_test.py b/tests/unit/job/job_test.py index abe98a15..717d1684 100644 --- a/tests/unit/job/job_test.py +++ b/tests/unit/job/job_test.py @@ -3,7 +3,7 @@ import pytest -from pyzeebe.common.exceptions import NoZeebeAdapter +from pyzeebe.exceptions import NoZeebeAdapter from pyzeebe.grpc_internals.zeebe_adapter import ZeebeAdapter from pyzeebe.job.job import Job from tests.unit.utils.random_utils import random_job diff --git a/tests/unit/worker/task_handler_test.py b/tests/unit/worker/task_handler_test.py index fd9ffec2..255ffe2b 100644 --- a/tests/unit/worker/task_handler_test.py +++ b/tests/unit/worker/task_handler_test.py @@ -3,7 +3,8 @@ import pytest -from pyzeebe.common.exceptions import TaskNotFound, NoVariableNameGiven +from pyzeebe.exceptions import NoVariableNameGiven +from pyzeebe.exceptions.pyzeebe_exceptions import TaskNotFound from pyzeebe.task.task import Task from pyzeebe.worker.task_handler import ZeebeTaskHandler, default_exception_handler from tests.unit.utils.random_utils import randint, random_job From 80b798fae498c3206e5105922aa43581ccd58b56 Mon Sep 17 00:00:00 2001 From: Jonatan Martens Date: Tue, 29 Sep 2020 11:57:33 +0300 Subject: [PATCH 6/9] [FIXED] some exceptions not exported --- pyzeebe/exceptions/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyzeebe/exceptions/__init__.py b/pyzeebe/exceptions/__init__.py index 6fa8e9b7..6de5300f 100644 --- a/pyzeebe/exceptions/__init__.py +++ b/pyzeebe/exceptions/__init__.py @@ -1,3 +1,5 @@ from .job_exceptions import * +from .message_exceptions import * from .pyzeebe_exceptions import * from .workflow_exceptions import * +from .zeebe_exceptions import * From 66a787112f07c2fcc7564608ec446b9091ab1843 Mon Sep 17 00:00:00 2001 From: Jonatan Martens Date: Tue, 29 Sep 2020 12:02:30 +0300 Subject: [PATCH 7/9] [FIXED] imports from pyzeebe.exceptions not pyzeebe.exceptions. --- pyzeebe/grpc_internals/zeebe_adapter_base.py | 2 +- pyzeebe/grpc_internals/zeebe_job_adapter.py | 5 ++--- pyzeebe/grpc_internals/zeebe_message_adapter.py | 2 +- pyzeebe/grpc_internals/zeebe_workflow_adapter.py | 5 ++--- pyzeebe/worker/task_handler.py | 3 +-- tests/integration/integration_test.py | 4 ++-- tests/unit/grpc_internals/zeebe_adapter_base_test.py | 2 +- tests/unit/grpc_internals/zeebe_message_adapter_test.py | 2 +- tests/unit/worker/task_handler_test.py | 3 +-- 9 files changed, 12 insertions(+), 16 deletions(-) diff --git a/pyzeebe/grpc_internals/zeebe_adapter_base.py b/pyzeebe/grpc_internals/zeebe_adapter_base.py index 396ddcfa..6c14f71a 100644 --- a/pyzeebe/grpc_internals/zeebe_adapter_base.py +++ b/pyzeebe/grpc_internals/zeebe_adapter_base.py @@ -4,7 +4,7 @@ import grpc from pyzeebe.credentials.base_credentials import BaseCredentials -from pyzeebe.exceptions.zeebe_exceptions import ZeebeBackPressure, ZeebeGatewayUnavailable, ZeebeInternalError +from pyzeebe.exceptions import ZeebeBackPressure, ZeebeGatewayUnavailable, ZeebeInternalError from pyzeebe.grpc_internals.zeebe_pb2_grpc import GatewayStub diff --git a/pyzeebe/grpc_internals/zeebe_job_adapter.py b/pyzeebe/grpc_internals/zeebe_job_adapter.py index 3eb739b3..b3af3d98 100644 --- a/pyzeebe/grpc_internals/zeebe_job_adapter.py +++ b/pyzeebe/grpc_internals/zeebe_job_adapter.py @@ -6,9 +6,8 @@ from pyzeebe.exceptions import ActivateJobsRequestInvalid, JobAlreadyDeactivated, JobNotFound from pyzeebe.grpc_internals.zeebe_adapter_base import ZeebeAdapterBase -from pyzeebe.grpc_internals.zeebe_pb2 import (ActivateJobsRequest, CompleteJobRequest, - CompleteJobResponse, FailJobRequest, FailJobResponse, ThrowErrorRequest, - ThrowErrorResponse) +from pyzeebe.grpc_internals.zeebe_pb2 import ActivateJobsRequest, CompleteJobRequest, CompleteJobResponse, \ + FailJobRequest, FailJobResponse, ThrowErrorRequest, ThrowErrorResponse from pyzeebe.job.job import Job diff --git a/pyzeebe/grpc_internals/zeebe_message_adapter.py b/pyzeebe/grpc_internals/zeebe_message_adapter.py index cdb6cc68..ce72f53e 100644 --- a/pyzeebe/grpc_internals/zeebe_message_adapter.py +++ b/pyzeebe/grpc_internals/zeebe_message_adapter.py @@ -3,7 +3,7 @@ import grpc -from pyzeebe.exceptions.message_exceptions import MessageAlreadyExists +from pyzeebe.exceptions import MessageAlreadyExists from pyzeebe.grpc_internals.zeebe_adapter_base import ZeebeAdapterBase from pyzeebe.grpc_internals.zeebe_pb2 import PublishMessageRequest, PublishMessageResponse diff --git a/pyzeebe/grpc_internals/zeebe_workflow_adapter.py b/pyzeebe/grpc_internals/zeebe_workflow_adapter.py index 28129688..30841541 100644 --- a/pyzeebe/grpc_internals/zeebe_workflow_adapter.py +++ b/pyzeebe/grpc_internals/zeebe_workflow_adapter.py @@ -7,9 +7,8 @@ from pyzeebe.exceptions import InvalidJSON, WorkflowNotFound, WorkflowInstanceNotFound, WorkflowHasNoStartEvent, \ WorkflowInvalid from pyzeebe.grpc_internals.zeebe_adapter_base import ZeebeAdapterBase -from pyzeebe.grpc_internals.zeebe_pb2 import (CreateWorkflowInstanceRequest, CreateWorkflowInstanceWithResultRequest, - CancelWorkflowInstanceRequest, WorkflowRequestObject, - DeployWorkflowRequest, DeployWorkflowResponse) +from pyzeebe.grpc_internals.zeebe_pb2 import CreateWorkflowInstanceRequest, CreateWorkflowInstanceWithResultRequest, \ + CancelWorkflowInstanceRequest, WorkflowRequestObject, DeployWorkflowRequest, DeployWorkflowResponse class ZeebeWorkflowAdapter(ZeebeAdapterBase): diff --git a/pyzeebe/worker/task_handler.py b/pyzeebe/worker/task_handler.py index b9d3ab37..889075ee 100644 --- a/pyzeebe/worker/task_handler.py +++ b/pyzeebe/worker/task_handler.py @@ -3,8 +3,7 @@ from typing import Tuple, List, Callable from pyzeebe.decorators.zeebe_decorator_base import ZeebeDecoratorBase -from pyzeebe.exceptions import NoVariableNameGiven -from pyzeebe.exceptions.pyzeebe_exceptions import TaskNotFound +from pyzeebe.exceptions import NoVariableNameGiven, TaskNotFound from pyzeebe.job.job import Job from pyzeebe.task.exception_handler import ExceptionHandler from pyzeebe.task.task import Task diff --git a/tests/integration/integration_test.py b/tests/integration/integration_test.py index f9897f5c..15db6335 100644 --- a/tests/integration/integration_test.py +++ b/tests/integration/integration_test.py @@ -5,8 +5,8 @@ import pytest -import pyzeebe.exceptions.workflow_exceptions from pyzeebe import ZeebeWorker, ZeebeClient, Job +from pyzeebe.exceptions import WorkflowNotFound zeebe_client: ZeebeClient zeebe_worker = ZeebeWorker() @@ -49,7 +49,7 @@ def test_run_workflow(): def test_non_existent_workflow(): - with pytest.raises(pyzeebe.exceptions.workflow_exceptions.WorkflowNotFound): + with pytest.raises(WorkflowNotFound): zeebe_client.run_workflow(str(uuid4())) diff --git a/tests/unit/grpc_internals/zeebe_adapter_base_test.py b/tests/unit/grpc_internals/zeebe_adapter_base_test.py index 1c96929f..d417bcad 100644 --- a/tests/unit/grpc_internals/zeebe_adapter_base_test.py +++ b/tests/unit/grpc_internals/zeebe_adapter_base_test.py @@ -4,7 +4,7 @@ from pyzeebe.credentials.camunda_cloud_credentials import CamundaCloudCredentials from pyzeebe.credentials.oauth_credentials import OAuthCredentials -from pyzeebe.exceptions.zeebe_exceptions import ZeebeBackPressure, ZeebeGatewayUnavailable, ZeebeInternalError +from pyzeebe.exceptions import ZeebeBackPressure, ZeebeGatewayUnavailable, ZeebeInternalError from pyzeebe.grpc_internals.zeebe_adapter_base import ZeebeAdapterBase from tests.unit.utils.grpc_utils import * from tests.unit.utils.random_utils import RANDOM_RANGE diff --git a/tests/unit/grpc_internals/zeebe_message_adapter_test.py b/tests/unit/grpc_internals/zeebe_message_adapter_test.py index bf84eda7..217a73a4 100644 --- a/tests/unit/grpc_internals/zeebe_message_adapter_test.py +++ b/tests/unit/grpc_internals/zeebe_message_adapter_test.py @@ -2,7 +2,7 @@ from unittest.mock import MagicMock from uuid import uuid4 -from pyzeebe.exceptions.message_exceptions import MessageAlreadyExists +from pyzeebe.exceptions import MessageAlreadyExists from pyzeebe.grpc_internals.zeebe_message_adapter import ZeebeMessageAdapter from pyzeebe.grpc_internals.zeebe_pb2 import * from tests.unit.utils.grpc_utils import * diff --git a/tests/unit/worker/task_handler_test.py b/tests/unit/worker/task_handler_test.py index 255ffe2b..8391c72d 100644 --- a/tests/unit/worker/task_handler_test.py +++ b/tests/unit/worker/task_handler_test.py @@ -3,8 +3,7 @@ import pytest -from pyzeebe.exceptions import NoVariableNameGiven -from pyzeebe.exceptions.pyzeebe_exceptions import TaskNotFound +from pyzeebe.exceptions import NoVariableNameGiven, TaskNotFound from pyzeebe.task.task import Task from pyzeebe.worker.task_handler import ZeebeTaskHandler, default_exception_handler from tests.unit.utils.random_utils import randint, random_job From dd4d1b70a8af0b2ad7e0bc16eabe75966228a4ee Mon Sep 17 00:00:00 2001 From: Jonatan Martens Date: Tue, 29 Sep 2020 12:19:29 +0300 Subject: [PATCH 8/9] [FIXED] Made get_params_from_function private and added tests for it --- pyzeebe/worker/task_handler.py | 10 ++++- pyzeebe/worker/task_router.py | 4 +- pyzeebe/worker/worker.py | 4 +- tests/unit/worker/task_handler_test.py | 62 ++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 6 deletions(-) diff --git a/pyzeebe/worker/task_handler.py b/pyzeebe/worker/task_handler.py index 889075ee..306865fe 100644 --- a/pyzeebe/worker/task_handler.py +++ b/pyzeebe/worker/task_handler.py @@ -69,8 +69,14 @@ def inner_fn(*args, **kwargs): return inner_fn @staticmethod - def get_variables_to_fetch_from_function(fn: Callable) -> List[str]: - return list(fn.__code__.co_varnames) + def _get_parameters_from_function(fn: Callable) -> List[str]: + parameters = fn.__code__.co_varnames + if "args" in parameters: + return [] + elif "kwargs" in parameters: + return [] + else: + return list(parameters) def remove_task(self, task_type: str) -> Task: task_index = self._get_task_index(task_type) diff --git a/pyzeebe/worker/task_router.py b/pyzeebe/worker/task_router.py index db504075..a5db9673 100644 --- a/pyzeebe/worker/task_router.py +++ b/pyzeebe/worker/task_router.py @@ -13,7 +13,7 @@ def _dict_task(self, task_type: str, exception_handler: ExceptionHandler = defau def wrapper(fn: Callable[..., Dict]): nonlocal variables_to_fetch if not variables_to_fetch: - variables_to_fetch = self.get_variables_to_fetch_from_function(fn) + variables_to_fetch = self._get_parameters_from_function(fn) task = self._create_task(task_type=task_type, task_handler=fn, exception_handler=exception_handler, timeout=timeout, max_jobs_to_activate=max_jobs_to_activate, before=before, @@ -31,7 +31,7 @@ def _non_dict_task(self, task_type: str, variable_name: str, def wrapper(fn: Callable[..., Dict]): nonlocal variables_to_fetch if not variables_to_fetch: - variables_to_fetch = self.get_variables_to_fetch_from_function(fn) + variables_to_fetch = self._get_parameters_from_function(fn) dict_fn = self._single_value_function_to_dict(variable_name=variable_name, fn=fn) diff --git a/pyzeebe/worker/worker.py b/pyzeebe/worker/worker.py index 9c47c47a..447209c1 100644 --- a/pyzeebe/worker/worker.py +++ b/pyzeebe/worker/worker.py @@ -78,7 +78,7 @@ def _dict_task(self, task_type: str, exception_handler: ExceptionHandler = defau def wrapper(fn: Callable[..., Dict]): nonlocal variables_to_fetch if not variables_to_fetch: - variables_to_fetch = self.get_variables_to_fetch_from_function(fn) + variables_to_fetch = self._get_parameters_from_function(fn) task = Task(task_type=task_type, task_handler=fn, exception_handler=exception_handler, timeout=timeout, max_jobs_to_activate=max_jobs_to_activate, before=before, after=after, @@ -95,7 +95,7 @@ def _non_dict_task(self, task_type: str, variable_name: str, def wrapper(fn: Callable[..., Dict]): nonlocal variables_to_fetch if not variables_to_fetch: - variables_to_fetch = self.get_variables_to_fetch_from_function(fn) + variables_to_fetch = self._get_parameters_from_function(fn) dict_fn = self._single_value_function_to_dict(variable_name=variable_name, fn=fn) diff --git a/tests/unit/worker/task_handler_test.py b/tests/unit/worker/task_handler_test.py index 8391c72d..4f42ecc5 100644 --- a/tests/unit/worker/task_handler_test.py +++ b/tests/unit/worker/task_handler_test.py @@ -116,3 +116,65 @@ def test_default_exception_handler(): failure_mock.assert_called() logging_mock.assert_called() + + +def test_get_parameters_from_function_no_parameters(): + def no_parameters(): + pass + + assert zeebe_task_handler._get_parameters_from_function(no_parameters) == [] + + +def test_get_parameters_from_function_one_positional(): + def one_pos_func(x): + pass + + assert zeebe_task_handler._get_parameters_from_function(one_pos_func) == ["x"] + + +def test_get_parameters_from_function_multiple_positional(): + def mul_pos_func(x, y, z): + pass + + assert zeebe_task_handler._get_parameters_from_function(mul_pos_func) == ["x", "y", "z"] + + +def test_get_parameters_from_function_one_keyword(): + def one_key_func(x=0): + pass + + assert zeebe_task_handler._get_parameters_from_function(one_key_func) == ["x"] + + +def test_get_parameters_from_function_multiple_keywords(): + def mul_key_func(x=0, y=0, z=0): + pass + + assert zeebe_task_handler._get_parameters_from_function(mul_key_func) == ["x", "y", "z"] + + +def test_get_parameters_from_function_positional_and_keyword(): + def pos_and_key_func(x, y=0): + pass + + assert zeebe_task_handler._get_parameters_from_function(pos_and_key_func) == ["x", "y"] + + +def test_get_parameters_from_function_args(): + def args_func(*args): + pass + + assert zeebe_task_handler._get_parameters_from_function(args_func) == [] + + +def test_get_parameters_from_function_kwargs(): + def kwargs_func(**kwargs): + pass + + assert zeebe_task_handler._get_parameters_from_function(kwargs_func) == [] + + +def test_get_parameters_from_function_lambda(): + my_func = lambda x: x + + assert zeebe_task_handler._get_parameters_from_function(my_func) == ["x"] From 716b246ed5f19e468b787b3a658537f339f84361 Mon Sep 17 00:00:00 2001 From: Jonatan Martens Date: Tue, 29 Sep 2020 12:23:02 +0300 Subject: [PATCH 9/9] [FIXED] Parameters documentation --- pyzeebe/worker/task_handler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyzeebe/worker/task_handler.py b/pyzeebe/worker/task_handler.py index 306865fe..13424203 100644 --- a/pyzeebe/worker/task_handler.py +++ b/pyzeebe/worker/task_handler.py @@ -31,9 +31,12 @@ def task(self, task_type: str, exception_handler: ExceptionHandler = default_exc variable_name: str = None): """Decorator to create a task single_value (bool): If the function returns a single value (int, string, list) and not a dictionary set this to - True. + True. Default: False variable_name (str): If single_value then this will be the variable name given to zeebe: { : } + timeout (int): Maximum duration of the task in milliseconds. If the timeout is surpasses Zeebe will give up + on the job and retry it. Default: 10000 + max_jobs_to_activate (int): Maximum jobs the worker will execute in parallel (of this task). Default: 32 """ if single_value and not variable_name: raise NoVariableNameGiven(task_type=task_type)