-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from mr-raccoon-97/main
Bump version
- Loading branch information
Showing
14 changed files
with
352 additions
and
37 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.github/workflows/python-publish.yml → .github/workflows/python-CD.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Python package | ||
name: CD | ||
on: | ||
push: | ||
branches: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: CI | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
tests: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.12"] | ||
poetry-version: ["latest", "1.8.3"] | ||
os: [ubuntu-22.04, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Run image | ||
uses: abatilo/actions-poetry@v2 | ||
with: | ||
poetry-version: ${{ matrix.poetry-version }} | ||
- name: Install dependencies | ||
run: poetry install | ||
- name: Test with pytest | ||
run: | | ||
poetry run pytest |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from pybondi.messagebus import Event | ||
from pybondi.messagebus import Command | ||
from pybondi.messagebus import Messagebus | ||
from pybondi.aggregate import Aggregate | ||
from pybondi.aggregate import Root | ||
from pybondi.aggregate import Factory | ||
from pybondi.session import Session | ||
from pybondi.publisher import Publisher | ||
from pybondi.repository import Repository | ||
from pybondi.callbacks import Callbacks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,111 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Any | ||
from typing import Sequence | ||
from mlbus.publisher import Publisher | ||
from pybondi.publisher import Publisher | ||
|
||
class Callback(ABC): | ||
''' | ||
Callbacks should be injected into the aggregate's methods to allow it to process | ||
data and communicate their results to the message publisher. | ||
''' | ||
|
||
def __init__(self): | ||
self.publisher = Publisher() | ||
|
||
def bind(self, publisher: Publisher): | ||
''' | ||
Bind a publisher to the callback object. | ||
''' | ||
self.publisher = publisher | ||
|
||
def set(self, name: str, value: Any) -> None: | ||
''' | ||
Set a value on the callback object. | ||
Paramaters: | ||
name: The name of the attribute. | ||
value: The value to set. | ||
''' | ||
setattr(self, name, value) | ||
|
||
@abstractmethod | ||
def __call__(self, *args, **kwargs): ... | ||
def __call__(self, *args, **kwargs): | ||
''' | ||
Call the callback object. Data from the aggregate's methods should be passed | ||
to the callback object through this method, and processed accordingly. | ||
The callback object should also communicate the results of the processing to | ||
the message publisher directly or should implement a buffer to store the results | ||
until the flush method is called. | ||
''' | ||
... | ||
|
||
@abstractmethod | ||
def flush(self): ... | ||
def flush(self): | ||
''' | ||
Flush the callback object. If the callback object has a buffer, the buffer should | ||
be flushed and the data should be sent to the message publisher. | ||
''' | ||
... | ||
|
||
@abstractmethod | ||
def reset(self): ... | ||
def reset(self): | ||
''' | ||
Reset the callback object. The callback object should reset any internal state | ||
that it maintains, if any. | ||
''' | ||
... | ||
|
||
|
||
class Callbacks: | ||
''' | ||
Callbacks is a class that manages a group of callback objects. It is responsible for | ||
calling the callback objects, flushing their buffers, and resetting their internal | ||
state, as if they were a single callback object. | ||
Example: | ||
callback = Callbacks([SomeCallback(), OtherCallback()) | ||
''' | ||
|
||
def __init__(self, callbacks: Sequence[Callback]): | ||
self.publisher = Publisher() | ||
self.list = list[Callback](callbacks) | ||
|
||
def set(self, name: str, value: Any) -> None: | ||
[setattr(callback, name, value) for callback in self.list] | ||
|
||
def bind(self, publisher: Publisher): | ||
''' | ||
Bind a publisher to all the callback objects. | ||
''' | ||
[callback.bind(publisher) for callback in self.list] | ||
|
||
def set(self, name: str, value: Any) -> None: | ||
''' | ||
Set a value to all the callback objects. | ||
Paramaters: | ||
name: The name of the attribute. | ||
value: The value to set. | ||
''' | ||
[callback.set(name, value) for callback in self.list] | ||
|
||
|
||
def __call__(self, *args, **kwargs): | ||
''' | ||
Call the callbacks. Data from the aggregate's methods should be passed | ||
to the callback objects through this method, and processed accordingly. | ||
''' | ||
[callback(*args, **kwargs) for callback in self.list] | ||
|
||
def flush(self): | ||
''' | ||
Flush the callbacks. If the callback objects have a buffer, the buffer should | ||
be flushed and the data should be sent to the message publisher. | ||
''' | ||
[callback.flush() for callback in self.list] | ||
|
||
def reset(self): | ||
''' | ||
Reset the callbacks. The callback objects should reset any internal state | ||
that they maintain, if any. | ||
''' | ||
[callback.reset() for callback in self.list] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.