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

fix: label issues #72

Merged
merged 8 commits into from
Apr 27, 2024
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
Loading