diff --git a/config/dev.exs b/config/dev.exs index 30ad5440..3adb4291 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -74,9 +74,6 @@ config :dpul_collections, DpulCollectionsWeb.Endpoint, ] ] -# Set environment -config :dpul_collections, :current_env, :dev - config :dpul_collections, :basic_auth_username, "admin" config :dpul_collections, :basic_auth_password, "admin" @@ -112,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, [ [ diff --git a/config/prod.exs b/config/prod.exs index fe4f8a80..0e1d1fb9 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -8,9 +8,6 @@ import Config config :dpul_collections, DpulCollectionsWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json" -# Set environment -config :dpul_collections, :current_env, :prod - # Enable dev routes - including mailbox preview and the dashboard. config :dpul_collections, dev_routes: true diff --git a/config/runtime.exs b/config/runtime.exs index 52abb5f5..7319fef2 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -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 diff --git a/config/test.exs b/config/test.exs index 4a4d04e4..8312ce3d 100644 --- a/config/test.exs +++ b/config/test.exs @@ -36,9 +36,6 @@ config :dpul_collections, DpulCollectionsWeb.Endpoint, # In test we don't send emails. config :dpul_collections, DpulCollections.Mailer, adapter: Swoosh.Adapters.Test -# Set environment -config :dpul_collections, :current_env, :test - # Set basic auth config :dpul_collections, :basic_auth_username, "admin" config :dpul_collections, :basic_auth_password, "test" @@ -67,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 diff --git a/lib/dpul_collections/application.ex b/lib/dpul_collections/application.ex index 015f1eae..677ee6cf 100644 --- a/lib/dpul_collections/application.ex +++ b/lib/dpul_collections/application.ex @@ -22,7 +22,7 @@ defmodule DpulCollections.Application do # Start to serve requests, typically the last entry DpulCollectionsWeb.Endpoint, DpulCollections.IndexMetricsTracker - ] ++ environment_children(Application.fetch_env!(:dpul_collections, :current_env)) + ] ++ filter_pipeline_children() # See https://hexdocs.pm/elixir/Supervisor.html # for other strategies and supported options @@ -30,23 +30,10 @@ defmodule DpulCollections.Application do 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 - - # 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 + def filter_pipeline_children() do + fun = Application.fetch_env!(:dpul_collections, :start_indexing_pipeline?) + if fun.() == true do indexing_pipeline_children() else []