Ejemplo n.º 1
0
    async def test_no_additional_variables_are_added_to_result(self, single_value_task_config: TaskConfig, mocked_job_with_adapter: Job):
        mocked_job_with_adapter.variables = {"x": 1}

        task = task_builder.build_task(lambda x: x, single_value_task_config)
        job = await task.job_handler(mocked_job_with_adapter)

        assert len(job.variables.keys()) == 1
        assert set(job.variables.keys()) == {"y"}
Ejemplo n.º 2
0
    async def test_parameters_are_provided_to_task(self, original_task_function: Callable, task_config: TaskConfig,
                                                   mocked_job_with_adapter: Job):
        mocked_job_with_adapter.variables = {"x": 1}
        job_handler = task_builder.build_job_handler(
            original_task_function, task_config)

        await job_handler(mocked_job_with_adapter)

        original_task_function.assert_called_with(x=1)
Ejemplo n.º 3
0
    async def job_handler(job: Job) -> Job:
        if task_config.job_parameter_name:
            job.variables[task_config.job_parameter_name] = create_copy(job)

        job = await before_decorator_runner(job)
        job.variables, succeeded = await run_original_task_function(
            prepared_task_function, task_config, job)
        job = await after_decorator_runner(job)
        if succeeded:
            await job.set_success_status()
        return job
Ejemplo n.º 4
0
    async def test_decorator_variables_are_added(self, original_task_function: Callable, decorator: TaskDecorator,
                                                 task_config: TaskConfig, mocked_job_with_adapter: Job):
        mocked_job_with_adapter.variables = {"x": 2}
        decorator_return_value = mocked_job_with_adapter
        decorator.return_value = decorator_return_value
        job_handler = task_builder.build_job_handler(
            original_task_function, task_config)

        job = await job_handler(mocked_job_with_adapter)

        assert "x" in job.variables
Ejemplo n.º 5
0
def random_job(status: JobStatus = JobStatus.Running) -> Job:
    return Job(key=randint(0, RANDOM_RANGE),
               _type=str(uuid4()),
               workflow_instance_key=randint(0, RANDOM_RANGE),
               bpmn_process_id=str(uuid4()),
               deadline=randint(0, RANDOM_RANGE),
               workflow_key=randint(0, RANDOM_RANGE),
               element_id=str(uuid4()),
               element_instance_key=randint(0, RANDOM_RANGE),
               custom_headers={},
               variables={},
               retries=randint(0, 3),
               status=status,
               workflow_definition_version=randint(0, 100),
               worker=str(uuid4()))
Ejemplo n.º 6
0
def example_exception_handler(exception: Exception, job: Job) -> None:
    print(exception)
    print(job)
    job.set_failure_status(
        f"Failed to run task {job.type}. Reason: {exception}")
Ejemplo n.º 7
0
def example_exception_handler(exception: Exception, job: Job) -> None:
    job.set_failure_status(f"Error: {exception}")
Ejemplo n.º 8
0
def exception_handler(exc: Exception, job: Job) -> None:
    job.set_error_status(f"Failed to run task {job.type}. Reason: {exc}")