Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a configured function to determine whether to start indexing #300

Merged
merged 2 commits into from
Jan 28, 2025
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
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