From 380b7f3a1b1654f216c69c6e701a923fbac633ad Mon Sep 17 00:00:00 2001 From: Fabrizio Sestito Date: Tue, 31 May 2022 14:35:41 +0200 Subject: [PATCH] Use failure context in rollup event handler --- .../application/event_handlers/rollup_event_handler.ex | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/trento/application/event_handlers/rollup_event_handler.ex b/lib/trento/application/event_handlers/rollup_event_handler.ex index 9ffaacad7e..3433c7d0db 100644 --- a/lib/trento/application/event_handlers/rollup_event_handler.ex +++ b/lib/trento/application/event_handlers/rollup_event_handler.ex @@ -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( @@ -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