Skip to content

Commit

Permalink
Merge branch 'main' into refactor/persistence-recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu authored May 1, 2024
2 parents a66c72d + f581ecf commit 6dcea77
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest, macos-latest] # eventually add `windows-latest`
# TODO: Replace with macos-latest when works again.
# https://github.com/actions/setup-python/issues/808
os: [ubuntu-latest, macos-12] # eventually add `windows-latest`
python-version: [3.8, 3.9, "3.10", "3.11"]

steps:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#---------------------------------------------------------------------------------------------

# Build with builder image to reduce image size
FROM python:3.10 as builder
FROM python:3.11 as builder
USER root
WORKDIR /wheels
COPY . .
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
install_requires=[
"click", # Use same version as eth-ape
"eth-ape>=0.7.0,<1.0",
"ethpm-types>=0.6.10", # lower pin only, `eth-ape` governs upper pin
"eth-pydantic-types", # Use same version as eth-ape
"pydantic_settings", # Use same version as eth-ape
"taskiq[metrics]>=0.10.4,<0.11.0",
Expand Down
10 changes: 9 additions & 1 deletion silverback/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,18 @@ def broker_task_decorator(

# Register user function as task handler with our broker
def add_taskiq_task(handler: Callable) -> AsyncTaskiqDecoratedTask:
labels = {"task_type": str(task_type)}

if container and isinstance(container, ContractEvent):
# Address is almost a certainty if the container is being used as a filter here.
if contract_address := getattr(container.contract, "address", None):
labels["contract_address"] = contract_address
labels["event_signature"] = container.abi.signature

broker_task = self.broker.register_task(
handler,
task_name=handler.__name__,
task_type=str(task_type),
**labels,
)

self.tasks[task_type].append(TaskData(container=container, handler=broker_task))
Expand Down
4 changes: 3 additions & 1 deletion silverback/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ def _create_label(self, message: TaskiqMessage) -> str:
return message.task_name

def pre_execute(self, message: TaskiqMessage) -> TaskiqMessage:
if not (task_type := message.labels.pop("task_type")):
if "task_type" not in message.labels:
return message # Not a silverback task

task_type = message.labels.pop("task_type")

try:
task_type = TaskType(task_type)
except ValueError:
Expand Down

0 comments on commit 6dcea77

Please sign in to comment.