Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ To start your Phoenix app:

Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.

> [!WARNING]
> Your app will fail when calling `mix phx.server` if `STOP_EVENTS_ENALBED` or `CR_CROWDING_ENABLED` are `true` unless:
>
> 1. `ExAws` can find AWS credentials (such as `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`)
> 2. S3 bucket and object environment variables retrieved by `config/config.exs` are available
> 3. Your credentials have permissions on those objects
>
> To circumvent these issues, set `STOP_EVENTS_ENALBED` and `CR_CROWDING_ENABLED` to `false`.


## Tests

To run the tests, first install and setup Colima, Docker, and docker-compose:
Expand Down
1 change: 1 addition & 0 deletions apps/state/lib/state/stop_event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule State.StopEvent do
"""
use State.Server,
indices: [:id, :trip_id, :stop_id, :route_id, :vehicle_id],
parser: Parse.StopEvents,
recordable: Model.StopEvent

alias Model.Route
Expand Down
5 changes: 5 additions & 0 deletions apps/state_mediator/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ config :state_mediator, :commuter_rail_crowding,
s3_object: {:system, "CR_CROWDING_S3_OBJECT"},
source: {:system, "CR_CROWING_SOURCE", "s3"}

config :state_mediator, :stop_events,
enabled: {:system, "STOP_EVENTS_ENABLED", "false"},
s3_bucket: {:system, "STOP_EVENTS_S3_BUCKET"},
s3_object: {:system, "STOP_EVENTS_S3_OBJECT"}

config :state_mediator, Realtime,
gtfs_url: {:system, "MBTA_GTFS_URL", "https://cdn.mbta.com/MBTA_GTFS.zip"},
alert_url: {:system, "ALERT_URL", "https://cdn.mbta.com/realtime/Alerts_enhanced.json"}
Expand Down
29 changes: 28 additions & 1 deletion apps/state_mediator/lib/state_mediator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ defmodule StateMediator do
crowding_children(
app_value(:commuter_rail_crowding, :enabled) == "true",
crowding_source
)
) ++
stop_event_children(app_value(:stop_events, :enabled) == "true")

# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
Expand Down Expand Up @@ -155,6 +156,32 @@ defmodule StateMediator do
[]
end

@spec stop_event_children(boolean()) :: [
:supervisor.child_spec() | {module(), term()} | module()
]
defp stop_event_children(true) do
Logger.info("#{__MODULE__} STOP_EVENTS_ENABLED=true")

[
{
StateMediator.S3Mediator,
[
spec_id: :stop_event_mediator,
bucket_arn: app_value(:stop_events, :s3_bucket),
object: app_value(:stop_events, :s3_object),
interval: 3 * 1_000,
sync_timeout: 30_000,
state: State.StopEvent
]
}
]
end

defp stop_event_children(false) do
Logger.info("#{__MODULE__} STOP_EVENTS_ENABLED=false")
[]
end

@doc false
def source_url(mod) do
case Application.get_env(:state_mediator, mod)[:source] do
Expand Down
2 changes: 1 addition & 1 deletion apps/state_mediator/lib/state_mediator/s3_mediator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ defmodule StateMediator.S3Mediator do
state
) do
Logger.warning(
"Received unknown response when getting commuter rail occupancies from S3: #{inspect(response)}"
"Received unknown response when fetching data via S3Mediator: #{inspect(response)}"
)

schedule_update(state)
Expand Down
Loading