-
-
Save taiansu/4d11c3b649cc9309baffe06add6c39b6 to your computer and use it in GitHub Desktop.
module is not available in :prod env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/example/elasticsearch.ex | |
defmodule Example.Elasticsearch do | |
alias Example.Repo | |
alias Example.Model.{Library, Book} | |
@elastic_url Application.get_env(:hobs, :elastic_url) | |
@elastic_index Application.get_env(:hobs, :elastic_index) | |
def reindex_libraries do | |
#... | |
end | |
def reindex_books do | |
#... | |
end | |
def clear_all do | |
#... | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/mix/tasks/elasticsearch.ex | |
defmodule Mix.Tasks.Example.Elasticsearch do | |
use Mix.Task | |
require Example.Elasticsearch | |
@shortdoc "Reindex elasticsearch with current data" | |
def run(_args) do | |
unless Application.get_env(:phoenix, :serve_endpoints) do | |
Mix.Task.run "app.start", [] | |
end | |
Example.Elasticsearch.clear_all | |
Example.Elasticsearch.reindex_libraries | |
Example.Elasticsearch.reindex_books | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment