Skip to content

Commit

Permalink
bug fix: xcom
Browse files Browse the repository at this point in the history
  • Loading branch information
goFrendiAsgard committed Dec 23, 2023
1 parent ea214b7 commit 4762a7e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
30 changes: 28 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -907,11 +907,37 @@ Parallel(set_xcom_cmd, set_xcom_py) >> Parallel(get_xcom_cmd, get_xcom_py) >> te
runner.register(test_xcom)
```

The example shows that `set-xcom-cmd` and `set-xcom-py` set XCom values `one` and `two` respectively.
The example shows that `set-xcom-cmd` and `set-xcom-py` set XCom values `one` and `two`, respectively.

On the other hand, `get-xcom-cmd` and `get-xcom-py` fetch the values and print them.

Furthermore, every Zrb Task has their return values saved as `__xcom['execution-id']['task-name']`.
Furthermore, every Zrb Task has its return values saved as `__xcom['execution-id']['task-name']`. Let's see the following example:

```python
from zrb import runner, Parallel, CmdTask, python_task

hello_cmd = CmdTask(
name='hello-cmd',
cmd='echo hello-cmd',
)

@python_task(
name='hello-py'
)
def hello_py(*args, **kwargs):
return 'hello-py'

hello = CmdTask(
name='hello',
cmd=[
'echo {{task.get_xcom("hello-cmd")}}',
'echo {{task.get_xcom("hello-py")}}',
],
)

Parallel(hello_cmd, hello_py) >> hello
runner.register(hello)
```


## Basic Example
Expand Down
3 changes: 2 additions & 1 deletion src/zrb/task/base_task/base_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ async def _run_and_check_all(
]
results = await asyncio.gather(*coroutines)
result = results[-1]
self.set_xcom(self.get_name(), f'{result}')
self._print_result(result)
return result
except Exception as e:
Expand Down Expand Up @@ -379,6 +378,8 @@ async def _cached_run(self, *args: Any, **kwargs: Any) -> Any:
self._increase_attempt()
await asyncio.sleep(self._retry_interval)
await self.on_retry()
self.set_xcom(self.get_name(), f'{result}')
self.log_debug(f'XCom: {self.__xcom}')
await self._mark_done()
return result

Expand Down

0 comments on commit 4762a7e

Please sign in to comment.