Skip to content

Commit

Permalink
Improve processing commands
Browse files Browse the repository at this point in the history
* If commands handler raises TerkaAddedToEntity exception, continue
  execution
  • Loading branch information
AndreyMarkinPPC committed Jan 31, 2024
1 parent 6c8d77d commit 364af2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion terka/service_layer/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def _process_extra_args(id, context, uow):
if comment := context.get("comment"):
uow.published_messages.append(
commands.CommentTask(id=id, text=comment))
if hours := context.get("time_spent"):
if hours := context.get("hours"):
uow.published_messages.append(commands.TrackTask(id=id, hours=hours))

@register(cmd=commands.ListTask)
Expand Down
11 changes: 8 additions & 3 deletions terka/service_layer/messagebus.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations
from typing import Type
import logging

from terka import exceptions
from terka.adapters import publisher
from terka.domain import commands, events
from terka.service_layer import unit_of_work, handlers
Expand Down Expand Up @@ -41,9 +43,12 @@ def handle(self, message: Message, context: dict = {}):
def handle_command(self, command: commands.Command,
context: dict) -> None:
handler = self.command_handlers[type(command)]
if result := handler(command, self, context):
self.return_value = result
self.queue.extend(self.uow.collect_new_events())
try:
if result := handler(command, self, context):
self.return_value = result
self.queue.extend(self.uow.collect_new_events())
except exceptions.TaskAddedToEntity:
logging.warning("Task already added to compound entity")

def handle_event(self, event: events.Event, context: dict) -> None:
for handler in self.event_handlers[type(event)]:
Expand Down

0 comments on commit 364af2c

Please sign in to comment.