Skip to content

Commit

Permalink
Merge branch 'camunda-community-hub:master' into feature/475-generate…
Browse files Browse the repository at this point in the history
…-python-class-interface-protobuf
  • Loading branch information
felicijus authored Sep 18, 2024
2 parents 86fb204 + 9621591 commit 290862d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
20 changes: 12 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion pyzeebe/job/job.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING, Any, Optional

from pyzeebe.job.job_status import JobStatus
from pyzeebe.types import Headers, Variables
Expand All @@ -25,6 +25,10 @@ class Job:
variables: Variables
tenant_id: Optional[str] = None
status: JobStatus = JobStatus.Running
task_result = None

def set_task_result(self, task_result: Any) -> None:
object.__setattr__(self, "task_result", task_result)

def _set_status(self, value: JobStatus) -> None:
object.__setattr__(self, "status", value)
Expand Down
1 change: 1 addition & 0 deletions pyzeebe/task/task_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async def job_handler(job: Job, job_controller: JobController) -> Job:
return_variables, succeeded = await run_original_task_function(
prepared_task_function, task_config, job, job_controller
)
job.set_task_result(return_variables)
await job_controller.set_running_after_decorators_status()
job = await after_decorator_runner(job)
if succeeded:
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/task/task_builder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,29 @@ async def test_after_decorator_called(

task_config.after.pop().assert_called_once()

@pytest.mark.asyncio
async def test_after_decorator_can_access_task_result(
self,
task_config: TaskConfig,
job: Job,
mocked_job_controller: JobController,
):
async def task_function():
return {"result": 1}

self.task_result = dict()

async def after_decorator(job: Job):
self.task_result = job.task_result
return job

task_config.after.append(after_decorator)
job_handler = task_builder.build_job_handler(task_function, task_config)

await job_handler(job, mocked_job_controller)

assert self.task_result == {"result": 1}

@pytest.mark.asyncio
async def test_failing_decorator_continues(
self,
Expand Down

0 comments on commit 290862d

Please sign in to comment.