extremely hacky fix for ES configuration
This commit is contained in:
parent
4d191f6431
commit
f93345ecef
|
@ -20,13 +20,18 @@ config :backend, BackendWeb.Endpoint,
|
||||||
|
|
||||||
config :backend, Backend.Repo, queue_target: 5000
|
config :backend, Backend.Repo, queue_target: 5000
|
||||||
|
|
||||||
|
instances_config_path =
|
||||||
|
if System.get_env("MIX_ENV") == "prod",
|
||||||
|
do: "lib/backend-2.2.0/priv/elasticsearch/instances.json",
|
||||||
|
else: "instances.json"
|
||||||
|
|
||||||
config :backend, Backend.Elasticsearch.Cluster,
|
config :backend, Backend.Elasticsearch.Cluster,
|
||||||
url: "http://localhost:9200",
|
url: "http://localhost:9200",
|
||||||
api: Elasticsearch.API.HTTP,
|
api: Elasticsearch.API.HTTP,
|
||||||
json_library: Jason,
|
json_library: Jason,
|
||||||
indexes: %{
|
indexes: %{
|
||||||
instances: %{
|
instances: %{
|
||||||
settings: "priv/elasticsearch/instances.json",
|
settings: instances_config_path,
|
||||||
store: Backend.Elasticsearch.Store,
|
store: Backend.Elasticsearch.Store,
|
||||||
sources: [Backend.Instance],
|
sources: [Backend.Instance],
|
||||||
bulk_page_size: 1000,
|
bulk_page_size: 1000,
|
||||||
|
|
|
@ -1,12 +1,24 @@
|
||||||
defmodule Backend.Release do
|
defmodule Backend.Release do
|
||||||
@app :backend
|
@app :backend
|
||||||
|
@start_apps [
|
||||||
|
:crypto,
|
||||||
|
:ssl,
|
||||||
|
:postgrex,
|
||||||
|
:ecto,
|
||||||
|
:elasticsearch,
|
||||||
|
@app
|
||||||
|
]
|
||||||
|
|
||||||
alias Elasticsearch.Index
|
# Ecto repos to start, if any
|
||||||
alias Backend.Elasticsearch.Cluster
|
@repos Application.get_env(:backend, :ecto_repos, [])
|
||||||
|
# Elasticsearch clusters to start
|
||||||
|
@clusters [Backend.Elasticsearch.Cluster]
|
||||||
|
# Elasticsearch indexes to build
|
||||||
|
@indexes [:instances]
|
||||||
|
|
||||||
def run_all do
|
def run_all do
|
||||||
migrate()
|
migrate()
|
||||||
index()
|
build_elasticsearch_indexes()
|
||||||
end
|
end
|
||||||
|
|
||||||
def migrate do
|
def migrate do
|
||||||
|
@ -15,20 +27,32 @@ defmodule Backend.Release do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def index do
|
|
||||||
# TODO: this isn't the right way to handle this.
|
|
||||||
# See https://github.com/danielberkompas/elasticsearch-elixir/issues/76
|
|
||||||
Application.ensure_all_started(@app)
|
|
||||||
IO.puts("Indexing...")
|
|
||||||
Index.hot_swap(Cluster, "instances")
|
|
||||||
IO.puts("Done indexing.")
|
|
||||||
:init.stop()
|
|
||||||
end
|
|
||||||
|
|
||||||
def rollback(repo, version) do
|
def rollback(repo, version) do
|
||||||
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
|
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build_elasticsearch_indexes() do
|
||||||
|
start_services()
|
||||||
|
IO.puts("Building indexes...")
|
||||||
|
Enum.each(@indexes, &Elasticsearch.Index.hot_swap(Backend.Elasticsearch.Cluster, &1))
|
||||||
|
stop_services()
|
||||||
|
end
|
||||||
|
|
||||||
|
# Ensure that all OTP apps, repos used by your Elasticsearch store,
|
||||||
|
# and your Elasticsearch Cluster(s) are started
|
||||||
|
defp start_services do
|
||||||
|
IO.puts("Starting dependencies...")
|
||||||
|
Enum.each(@start_apps, &Application.ensure_all_started/1)
|
||||||
|
IO.puts("Starting repos...")
|
||||||
|
Enum.each(@repos, & &1.start_link(pool_size: 1))
|
||||||
|
IO.puts("Starting clusters...")
|
||||||
|
Enum.each(@clusters, & &1.start_link())
|
||||||
|
end
|
||||||
|
|
||||||
|
defp stop_services do
|
||||||
|
:init.stop()
|
||||||
|
end
|
||||||
|
|
||||||
defp repos do
|
defp repos do
|
||||||
Application.load(@app)
|
Application.load(@app)
|
||||||
Application.fetch_env!(@app, :ecto_repos)
|
Application.fetch_env!(@app, :ecto_repos)
|
||||||
|
|
Loading…
Reference in a new issue