Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: allow multiple handlers #66

Merged
merged 19 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a370d3a
refactor: add TaskType enum to types
fubuloubu Apr 8, 2024
7fd52d9
refactor!: use task collection by task type; use dynamic registration
fubuloubu Apr 8, 2024
144a087
refactor: use new task collections api for fetch task handlers
fubuloubu Apr 8, 2024
8ddb0d3
refactor!: use task type to differentiate tasks in middleware, not name
fubuloubu Apr 8, 2024
64c281e
fix: typing bugs, not using Union for 3.8 support
fubuloubu Apr 8, 2024
42247be
fix: use task type to capture event logs
fubuloubu Apr 9, 2024
e0c3dc7
refactor: use defaultdict instead of custom collection type
fubuloubu Apr 9, 2024
8798669
refactor: use standardized labels, use task_name for task_id
fubuloubu Apr 9, 2024
2a7d62a
refactor: remove `.task_name` from message labels
fubuloubu Apr 9, 2024
6aafc83
refactor: convert to TaskType for better processing
fubuloubu Apr 9, 2024
1bf0702
Merge branch 'main' into refactor/allow-multiple-handlers
fubuloubu Apr 10, 2024
5ad9b7a
refactor: use StrEnum if available
fubuloubu Apr 10, 2024
c177a94
docs: add note to deprecate in breaking change
fubuloubu Apr 10, 2024
eadaea5
refactor: make object type clearer when working with labels in middle…
fubuloubu Apr 10, 2024
9519b30
refactor: use official backport
fubuloubu Apr 10, 2024
184a939
docs: update typing and add docs for dynamic broker task decorator fn
fubuloubu Apr 10, 2024
77a11aa
style: ignore mypy typing issues on <3.11
fubuloubu Apr 11, 2024
9ca7692
refactor: avoid div/0 fault, fix duplicate log entry for results w/errs
fubuloubu Apr 11, 2024
897cf95
refactor: rollback weird typing backport issue
fubuloubu Apr 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions silverback/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def on_startup(self) -> Callable:
def do_something_on_startup(startup_state):
... # Reprocess missed events or blocks
"""
return self.broker_task_decorator(TaskType.STARTUP)
return self.broker_task_decorator(TaskType.STARTUP) # type: ignore[arg-type]

def on_shutdown(self) -> Callable:
"""
Expand All @@ -151,7 +151,7 @@ def on_shutdown(self) -> Callable:
def do_something_on_shutdown():
... # Record final state of app
"""
return self.broker_task_decorator(TaskType.SHUTDOWN)
return self.broker_task_decorator(TaskType.SHUTDOWN) # type: ignore[arg-type]
fubuloubu marked this conversation as resolved.
Show resolved Hide resolved

def on_worker_startup(self) -> Callable:
"""
Expand Down Expand Up @@ -210,7 +210,10 @@ def on_(
else:
self.poll_settings["_blocks_"] = {"start_block": start_block}

return self.broker_task_decorator(TaskType.NEW_BLOCKS, container=container)
return self.broker_task_decorator(
TaskType.NEW_BLOCKS, # type: ignore[arg-type]
container=container,
)

elif isinstance(container, ContractEvent) and isinstance(
container.contract, ContractInstance
Expand All @@ -229,7 +232,10 @@ def on_(
else:
self.poll_settings[key] = {"start_block": start_block}

return self.broker_task_decorator(TaskType.EVENT_LOG, container=container)
return self.broker_task_decorator(
TaskType.EVENT_LOG, # type: ignore[arg-type]
container=container,
)

# TODO: Support account transaction polling
# TODO: Support mempool polling
Expand Down
5 changes: 3 additions & 2 deletions silverback/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from typing_extensions import Self # Introduced 3.11

try:
from enum import StrEnum # Only Python 3.11+
# NOTE: Only Python 3.11+
from enum import StrEnum # type: ignore[attr-defined]

except ImportError:
from backports.strenum import StrEnum # type: ignore[no-redef]
from backports.strenum import StrEnum # type: ignore[no-redef,import-not-found]


class TaskType(StrEnum):
Expand Down
Loading