From c4e100113d90b41bee399cbad39e92df543cd2c5 Mon Sep 17 00:00:00 2001 From: Skander Mzali Date: Tue, 10 Sep 2024 13:04:47 -0700 Subject: [PATCH 1/2] Move image env to prod-only in runtime with default dev config --- server/config/dev.exs | 4 ++++ server/config/runtime.exs | 9 +++++---- server/lib/orcasite/radio/feed.ex | 1 - 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/server/config/dev.exs b/server/config/dev.exs index 9b2d7d21..c7f16ab5 100644 --- a/server/config/dev.exs +++ b/server/config/dev.exs @@ -109,3 +109,7 @@ config :ex_aws, :instance_role ], region: "us-west-2" + +config :orcasite, + audio_image_bucket: System.get_env("ORCASITE_AUDIO_IMAGE_BUCKET", "dev-audio-viz"), + audio_image_bucket_region: System.get_env("ORCASITE_AUDIO_IMAGE_BUCKET_REGION", "us-west-2") diff --git a/server/config/runtime.exs b/server/config/runtime.exs index c92645ca..aae1057c 100644 --- a/server/config/runtime.exs +++ b/server/config/runtime.exs @@ -17,10 +17,6 @@ import Config # Alternatively, you can use `mix phx.gen.release` to generate a `bin/server` # script that automatically sets the env var above. -config :orcasite, - audio_image_bucket: System.get_env("ORCASITE_AUDIO_IMAGE_BUCKET", "audio-deriv-orcasound-net"), - audio_image_bucket_region: System.get_env("ORCASITE_AUDIO_IMAGE_BUCKET_REGION", "us-west-2") - if System.get_env("PHX_SERVER") do config :orcasite, OrcasiteWeb.Endpoint, server: true end @@ -91,4 +87,9 @@ if config_env() == :prod do end config :swoosh, :api_client, Swoosh.ApiClient.Finch + + config :orcasite, + audio_image_bucket: + System.get_env("ORCASITE_AUDIO_IMAGE_BUCKET", "audio-deriv-orcasound-net"), + audio_image_bucket_region: System.get_env("ORCASITE_AUDIO_IMAGE_BUCKET_REGION", "us-west-2") end diff --git a/server/lib/orcasite/radio/feed.ex b/server/lib/orcasite/radio/feed.ex index 7d59ab55..cd4bb739 100644 --- a/server/lib/orcasite/radio/feed.ex +++ b/server/lib/orcasite/radio/feed.ex @@ -207,7 +207,6 @@ defmodule Orcasite.Radio.Feed do on_no_match: {:create, :for_feed_segment}, on_match: :ignore ) - |> IO.inspect(label: "new change") end) end end From a8a3176f3b5f8109db19c21a8b6e1fde63c6dd6e Mon Sep 17 00:00:00 2001 From: Skander Mzali Date: Tue, 10 Sep 2024 14:00:35 -0700 Subject: [PATCH 2/2] Use the bucket input in the SQS queue consumer when creating feed_streams --- server/lib/orcasite/radio/feed_stream.ex | 7 ++++++- server/lib/orcasite/radio/feed_stream_queue.ex | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/server/lib/orcasite/radio/feed_stream.ex b/server/lib/orcasite/radio/feed_stream.ex index 8a878bd5..e44fee92 100644 --- a/server/lib/orcasite/radio/feed_stream.ex +++ b/server/lib/orcasite/radio/feed_stream.ex @@ -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 @@ -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 = @@ -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 diff --git a/server/lib/orcasite/radio/feed_stream_queue.ex b/server/lib/orcasite/radio/feed_stream_queue.ex index f63c02f4..66923618 100644 --- a/server/lib/orcasite/radio/feed_stream_queue.ex +++ b/server/lib/orcasite/radio/feed_stream_queue.ex @@ -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