Skip to content

Commit

Permalink
Make populate a stream with max concurrency of 1
Browse files Browse the repository at this point in the history
  • Loading branch information
skanderm committed May 24, 2024
1 parent ace811d commit b425f01
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions server/lib/orcasite/global_setup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ defmodule Orcasite.GlobalSetup do
Orcasite.Radio.Feed
|> Ash.Query.for_read(:read)
|> Orcasite.Radio.read!()
|> Enum.map(fn feed ->
with {:ok, %{timestamps: timestamps}} <- Orcasite.Radio.AwsClient.list_timestamps(feed) do
timestamps
|> Enum.map(&%{feed: feed, playlist_timestamp: &1})
|> Orcasite.Radio.bulk_create(Orcasite.Radio.FeedStream, :create)
end
end)
|> Task.async_stream(
fn feed ->
with {:ok, %{timestamps: timestamps}} <- Orcasite.Radio.AwsClient.list_timestamps(feed) do
timestamps
|> Enum.map(&%{feed: feed, playlist_timestamp: &1})
|> Orcasite.Radio.bulk_create(Orcasite.Radio.FeedStream, :create)
end
end,
max_concurrency: 1
)
|> Enum.to_list()
end
end

0 comments on commit b425f01

Please sign in to comment.