diff --git a/lib/casts/db_feed.ex b/lib/casts/db_feed.ex index 35a57db..1f77297 100644 --- a/lib/casts/db_feed.ex +++ b/lib/casts/db_feed.ex @@ -2,13 +2,7 @@ defmodule Essig.Casts.DbFeed do use Essig.Repo def hydrate_cast(module) do - scope_uuid = Essig.Context.current_scope() - - query = - from e in Essig.Schemas.Event, where: e.scope_uuid == ^scope_uuid, order_by: [asc: :id] - - stream = query |> Repo.cursor_based_stream(max_rows: 100) - + stream = scoped_events() |> Repo.cursor_based_stream(max_rows: 100) Essig.Casts.CastRunner.send_events(module, stream) Enum.reduce(stream, %{}, fn _event, _acc -> @@ -17,4 +11,9 @@ defmodule Essig.Casts.DbFeed do # %TestReportProcess{entity | seq: event.seq} end) end + + def scoped_events do + scope_uuid = Essig.Context.current_scope() + from e in Essig.Schemas.Event, where: e.scope_uuid == ^scope_uuid, order_by: [asc: :id] + end end