Skip to content

Commit

Permalink
Use failure context in rollup event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziosestito committed May 31, 2022
1 parent 37bda09 commit 380b7f3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/trento/application/event_handlers/rollup_event_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ defmodule Trento.RollupEventHandler do
name: "roll_up_event_handler",
consistency: :strong

use Trento.Support.EventHandlerFailureContext,
after_max_retries_reached: &after_max_retries_reached/3

alias Trento.Rollup

alias Trento.Domain.Commands.AbortClusterRollup
alias Trento.Domain.Events.ClusterRolledUp

def handle(
Expand All @@ -18,4 +22,10 @@ defmodule Trento.RollupEventHandler do
) do
Rollup.rollup_aggregate(cluster_id, event)
end

defp after_max_retries_reached(%ClusterRolledUp{cluster_id: cluster_id}, _, _) do
%{cluster_id: cluster_id}
|> AbortClusterRollup.new!()
|> Trento.Commanded.dispatch()
end
end

0 comments on commit 380b7f3

Please sign in to comment.