Esempio n. 1
0
    def test_before_decorators_are_async(self, task_type: str):
        task_config = TaskConfig(task_type, self.exception_handler, 10000, 32,
                                 32, [], False, "",
                                 [self.sync_decorator, self.async_decorator],
                                 [])

        assert functions_are_all_async(task_config.before)
Esempio n. 2
0
    async def test_job_parameter_is_injected(self, task_config: TaskConfig, mocked_job_with_adapter: Job):
        task_config.job_parameter_name = "job"

        job_handler = task_builder.build_job_handler(
            self.function_with_job_parameter, task_config
        )
        job = await job_handler(mocked_job_with_adapter)

        assert job.variables["job"] == mocked_job_with_adapter
Esempio n. 3
0
    async def test_job_parameter_retains_variables(self, task_config: TaskConfig, mocked_job_with_adapter: Job):
        task_config.job_parameter_name = "job"
        expected_variables = copy.copy(mocked_job_with_adapter.variables)

        job_handler = task_builder.build_job_handler(
            self.function_with_job_parameter, task_config
        )
        job = await job_handler(mocked_job_with_adapter)

        assert job.variables["job"].variables == expected_variables
Esempio n. 4
0
def task_config(task_type):
    return TaskConfig(
        type=task_type,
        exception_handler=AsyncMock(),
        timeout_ms=10000,
        max_jobs_to_activate=32,
        max_running_jobs=32,
        variables_to_fetch=[],
        single_value=False,
        variable_name="",
        before=[],
        after=[],
    )
Esempio n. 5
0
 def _add_decorators_to_config(self, config: TaskConfig) -> TaskConfig:
     new_task_config = TaskConfig(
         type=config.type,
         exception_handler=config.exception_handler,
         timeout_ms=config.timeout_ms,
         max_jobs_to_activate=config.max_jobs_to_activate,
         max_running_jobs=config.max_running_jobs,
         variables_to_fetch=config.variables_to_fetch,
         single_value=config.single_value,
         variable_name=config.variable_name,
         before=self._before + config.before,  # type: ignore
         after=config.after + self._after  # type: ignore
     )
     return new_task_config
Esempio n. 6
0
def random_job(task: Task = task_builder.build_task(
    lambda x: {"x": x},
    TaskConfig("test", lambda: None, 10000, 32, 32, [], False, "", [], [])),
               zeebe_adapter: ZeebeAdapter = None) -> Job:
    return Job(_type=task.type,
               key=randint(0, RANDOM_RANGE),
               worker=str(uuid4()),
               retries=randint(0, 10),
               process_instance_key=randint(0, RANDOM_RANGE),
               bpmn_process_id=str(uuid4()),
               process_definition_version=randint(0, 100),
               process_definition_key=randint(0, RANDOM_RANGE),
               element_id=str(uuid4()),
               element_instance_key=randint(0, RANDOM_RANGE),
               variables={},
               custom_headers={},
               deadline=randint(0, RANDOM_RANGE),
               zeebe_adapter=zeebe_adapter)
Esempio n. 7
0
        def task_wrapper(task_function: Callable):
            config = TaskConfig(
                task_type,
                exception_handler,
                timeout_ms,
                max_jobs_to_activate,
                max_running_jobs,
                variables_to_fetch
                or parameter_tools.get_parameters_from_function(task_function),
                single_value,
                variable_name or "",
                before or [],
                after or [],
            )
            config_with_decorators = self._add_decorators_to_config(config)

            task = task_builder.build_task(task_function,
                                           config_with_decorators)
            self._add_task(task)
            return task_function
Esempio n. 8
0
def build_task(task_function: Function, task_config: TaskConfig) -> Task:
    task_config.job_parameter_name = get_job_parameter_name(task_function)
    return Task(task_function, build_job_handler(task_function, task_config),
                task_config)
Esempio n. 9
0
    def single_value_task_config(self, task_config: TaskConfig):
        task_config.single_value = True
        task_config.variable_name = "y"

        return task_config