-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule BookStore.BookStateHydrator do | ||
use GenServer, restart: :transient | ||
|
||
require Logger | ||
|
||
alias BookStore.Books.Book | ||
alias BookStore.BookDynamicSupervisor | ||
|
||
def start_link(state) do | ||
GenServer.start_link(__MODULE__, state, name: __MODULE__, timeout: 10_000) | ||
end | ||
|
||
@impl true | ||
def init(_) do | ||
Logger.info("#{inspect(Time.utc_now())} Starting Books process hydration") | ||
|
||
BookStore.Books.all() | ||
|> Enum.each(fn %Book{} = book -> | ||
BookDynamicSupervisor.add_book_to_supervisor(book) | ||
end) | ||
|
||
Logger.info("#{inspect(Time.utc_now())} Completed Books process hydration") | ||
|
||
:ignore | ||
end | ||
end |