Skip to content

Instantly share code, notes, and snippets.

@taiansu
Last active November 23, 2016 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taiansu/4d11c3b649cc9309baffe06add6c39b6 to your computer and use it in GitHub Desktop.
Save taiansu/4d11c3b649cc9309baffe06add6c39b6 to your computer and use it in GitHub Desktop.
module is not available in :prod env
# 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
# 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