Skip to content

Commit

Permalink
Merge pull request #300 from pulibrary/299-environment-config
Browse files Browse the repository at this point in the history
Use a configured function to determine whether to start indexing
  • Loading branch information
tpendragon authored Jan 28, 2025
2 parents 6815f73 + 0c7bb8a commit be3851b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
6 changes: 6 additions & 0 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ config :dpul_collections, :solr, %{
password: System.get_env("SOLR_PASSWORD") || "pass"
}

# only run indexing children if the webserver is running
# wrap this in a function b/c Phoenix.Endpoint.server? is not defined at config time
config :dpul_collections, :start_indexing_pipeline?, fn ->
Phoenix.Endpoint.server?(:dpul_collections, DpulCollectionsWeb.Endpoint)
end

# Configure indexing pipeline writes
config :dpul_collections, DpulCollections.IndexingPipeline, [
[
Expand Down
12 changes: 8 additions & 4 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,14 @@ if config_env() == :prod do

config :dpul_collections, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")

if System.get_env("INDEXER") do
config :dpul_collections, :start_indexing_pipeline, true
else
config :dpul_collections, :start_indexing_pipeline, false
# only run indexing children if the webserver is running
# wrap this in a function b/c the dev implementation requires it
config :dpul_collections, :start_indexing_pipeline?, fn ->
if System.get_env("INDEXER") do
true
else
false
end
end

# Configure basic auth
Expand Down
4 changes: 4 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ config :dpul_collections, :solr, %{
password: "SolrRocks"
}

# don't run indexing children
# wrap this in a function b/c the dev implementation requires it
config :dpul_collections, :start_indexing_pipeline?, fn -> false end

# Set this poll interval really small so it triggers in test.
config :dpul_collections, :figgy_hydrator, poll_interval: 50

Expand Down
20 changes: 4 additions & 16 deletions lib/dpul_collections/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,19 @@ defmodule DpulCollections.Application do
# Start to serve requests, typically the last entry
DpulCollectionsWeb.Endpoint,
DpulCollections.IndexMetricsTracker
] ++ environment_children(Mix.env())
] ++ filter_pipeline_children()

# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: DpulCollections.Supervisor]
Supervisor.start_link(children, opts)
end

def environment_children(:test) do
[]
end

# coveralls-ignore-start
# In development, start the indexing pipeline when the phoenix server starts.
def environment_children(:dev) do
if Phoenix.Endpoint.server?(:dpul_collections, DpulCollectionsWeb.Endpoint) do
indexing_pipeline_children()
else
[]
end
end
def filter_pipeline_children() do
fun = Application.fetch_env!(:dpul_collections, :start_indexing_pipeline?)

# In production, start the indexing pipeline if it's configured to be started
def environment_children(:prod) do
if Application.fetch_env!(:dpul_collections, :start_indexing_pipeline) == true do
if fun.() == true do
indexing_pipeline_children()
else
[]
Expand Down

0 comments on commit be3851b

Please sign in to comment.