-
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.
- Loading branch information
Showing
32 changed files
with
546 additions
and
133 deletions.
There are no files selected for viewing
This file was deleted.
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,15 @@ | ||
gendocs: docs/generated/output README.md | ||
|
||
gendocs-auto: | ||
while true; do \ | ||
make gendocs; \ | ||
inotifywait -e modify **/*.py; \ | ||
done | ||
|
||
docs/generated/output: docs/generated/getting_started.py docs/generated/_docgen.py | ||
cd docs/generated && poetry run python _docgen.py getting_started.py | ||
|
||
README.md: docs/generated/README.md examples/readme.py docs/generated/_genreadme.py | ||
cd docs/generated && poetry run python _genreadme.py | ||
|
||
.PHONY: gendocs gendocs-auto |
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
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from typing import ( | ||
TYPE_CHECKING, | ||
Generic, | ||
List, | ||
Optional, | ||
TypeVar, | ||
) | ||
|
||
from ._interfaces import ( | ||
CallMiddleware, | ||
LockProvider, | ||
MessageHandlerRegisterProtocol, | ||
MessagePartitioner, | ||
MessageProtocol, | ||
SubscriptionErrorHandler, | ||
SubscriptionStateProvider, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from ._aggregated_stream import AggregatedStream | ||
from ._message_store import MessageStore | ||
from ._subscription import Subscription | ||
|
||
E = TypeVar("E", bound=MessageProtocol) | ||
|
||
|
||
class AggregatedStreamFactory(Generic[E]): | ||
def __init__(self, store: "MessageStore[E]"): | ||
self._store = store | ||
|
||
def __call__( | ||
self, | ||
name: str, | ||
partitioner: "MessagePartitioner[E]", | ||
stream_wildcards: List[str], | ||
) -> "AggregatedStream[E]": | ||
""" | ||
Create an aggregated stream. | ||
Args: | ||
name: The name of the stream | ||
partitioner: A partitioner for the stream | ||
stream_wildcards: A list of stream wildcards to be aggregated | ||
""" | ||
from ._aggregated_stream import AggregatedStream | ||
|
||
return AggregatedStream( | ||
store=self._store, | ||
name=name, | ||
partitioner=partitioner, | ||
stream_wildcards=stream_wildcards, | ||
) | ||
|
||
|
||
class SubscriptionFactory(Generic[E]): | ||
def __init__(self, stream: "AggregatedStream[E]"): | ||
self._stream = stream | ||
|
||
def __call__( | ||
self, | ||
name: str, | ||
handlers: MessageHandlerRegisterProtocol[E] = None, | ||
call_middleware: Optional[CallMiddleware] = None, | ||
error_handler: Optional[SubscriptionErrorHandler] = None, | ||
state_provider: Optional[SubscriptionStateProvider] = None, | ||
lock_provider: Optional[LockProvider] = None, | ||
) -> "Subscription[E]": | ||
""" | ||
Create a subscription. | ||
Args: | ||
name: The name of the subscription | ||
handlers: Handlers to be called when a message is received | ||
call_middleware: A middleware to be called before the handlers | ||
error_handler: A handler for errors raised by the handlers | ||
state_provider: A provider for the subscription state | ||
lock_provider: A provider for the subscription locks | ||
""" | ||
from ._message_handler import MessageHandlerRegister | ||
from ._subscription import Subscription, SubscriptionMessageHandler | ||
|
||
if handlers is None: | ||
# allow constructing a subscription without handlers | ||
handlers = MessageHandlerRegister() | ||
|
||
return Subscription( | ||
name=name, | ||
stream=self._stream, | ||
message_handler=SubscriptionMessageHandler( | ||
handler_register=handlers, | ||
call_middleware=call_middleware, | ||
error_handler=error_handler, | ||
), | ||
state_provider=state_provider, | ||
lock_provider=lock_provider, | ||
) |
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
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.