Skip to content

Commit

Permalink
Use the bucket input in the SQS queue consumer when creating feed_str…
Browse files Browse the repository at this point in the history
…eams
  • Loading branch information
skanderm committed Sep 10, 2024
1 parent c4e1001 commit a8a3176
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion server/lib/orcasite/radio/feed_stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ defmodule Orcasite.Radio.FeedStream do

attribute :playlist_m3u8_path, :string do
public? true

description "S3 object path for playlist file (e.g. /rpi_orcasound_lab/hls/1541027406/live.m3u8)"
end

Expand Down Expand Up @@ -103,6 +104,7 @@ defmodule Orcasite.Radio.FeedStream do
argument :playlist_path, :string
argument :update_segments?, :boolean, default: false
argument :link_streams?, :boolean, default: false
argument :bucket, :string

change fn changeset, _context ->
path =
Expand Down Expand Up @@ -145,12 +147,15 @@ defmodule Orcasite.Radio.FeedStream do
changeset
|> Ash.Changeset.get_argument_or_attribute(:playlist_timestamp)

bucket_arg = Ash.Changeset.get_argument(changeset, :bucket)

feed
|> Map.take([:bucket, :bucket_region, :cloudfront_url])
|> Map.take([:bucket_region, :cloudfront_url])
|> Enum.reduce(changeset, fn {attribute, value}, acc ->
acc
|> Ash.Changeset.change_new_attribute(attribute, value)
end)
|> Ash.Changeset.change_new_attribute(:bucket, bucket_arg || feed.bucket)
|> Ash.Changeset.change_new_attribute(
:start_time,
playlist_timestamp
Expand Down
9 changes: 7 additions & 2 deletions server/lib/orcasite/radio/feed_stream_queue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ defmodule Orcasite.Radio.FeedStreamQueue do
[]
end
end)
|> Enum.flat_map(fn %{"s3" => %{"object" => %{"key" => object_path}}} ->
|> Enum.flat_map(fn %{
"s3" => %{
"object" => %{"key" => object_path},
"bucket" => %{"name" => bucket}
}
} ->
if String.ends_with?(object_path, ".m3u8") and
select_recent_timestamp(object_path, ~U[2024-09-09 00:00:00Z]) do
[%{m3u8_path: object_path}]
[%{m3u8_path: object_path, bucket: bucket}]
else
[]
end
Expand Down

0 comments on commit a8a3176

Please sign in to comment.