ak-iz

ak-iz

How do I deploy project with Amnesia with `mix release` on production?

I have multiple disk schemas with Amnesia. But for some reason it doesn’t work when I deploy with mix release.

I have this in my Application module:

def start(_type, _args) do
    children = [
      MyApp.CacheInitializer
    ]
  end

This is my CacheInitializer module.

defmodule MyApp.CacheInitializer do
  use Task, restart: :permanent

  @spec start_link(any()) :: :ignore | {:error, any()} | {:ok, pid()}
  def start_link(_init_args \\ []) do
    Task.start_link(__MODULE__, :run, [])
  end

  def run() do
    if Application.get_env(:my_app, :app_config)[:env] == :prod do
      MyApp.CacheBuilder.build()
    else
      Process.sleep(:infinity)
    end
  end
end

MyApp.CacheBuilder.build() starts to write on the Amnesia tables. For dev, when I run with iex it works fine (also changing the if condition so it can work with dev). There I run command: mix amnesia.create -d Database --disk!.

The error I get when I run my release through start is:

15:14:52.447 [error] Task #PID<0.4991.0> started from MyApp.Supervisor terminating
** (stop) {:aborted, {:no_exists, Database.InValidRssCache}}
    (mnesia 4.18.1) mnesia.erl:361: :mnesia.abort/1
    (mnesia 4.18.1) mnesia_tm.erl:1067: :mnesia_tm.dirty/2
    (my_app 0.0.1) lib/my_app/amensia/database.ex:32: Database.InValidRssCache.write!/1
    (my_app 0.0.1) lib/my_app/invalid_rss_cache.ex:14: MyApp.InvalidRssCache.write!/2
    (elixir 1.13.4) lib/enum.ex:937: Enum."-each/2-lists^foreach/1-0-"/2
    (my_app 0.0.1) lib/my_app/cache_builder.ex:15: MyApp.CacheBuilder.build/0
    (elixir 1.13.4) lib/task/supervised.ex:89: Task.Supervised.invoke_mfa/2
    (stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Function: &MyApp.CacheInitializer.run/0
    Args: []
{"Kernel pid terminated",application_controller,"{application_terminated,my_app,shutdown}"}
Kernel pid terminated (application_controller) ({application_terminated,my_app,shutdown})

Crash dump is being written to: erl_crash.dump...done

I also start my release with $BOOT_SCRIPT_CLEAN, running Amnesia.start doesn’t help anything, as soon as I run my application, I get the same error.

Is there something else needs to be done here? Or is there a way I can run my application having Amnesia with mix release? Any help?

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New

We're in Beta

About us Mission Statement