elixir-web / weber

[WiP] Web framework for Elixir inspired by Rails [#WeberMVC at freenode]
http://elixir-web.github.io/weber/
MIT License
370 stars 33 forks source link

Configuration for using Ecto with Weber #174

Closed AxisOfEval closed 10 years ago

AxisOfEval commented 10 years ago

The Ecto Readme explicitly mentions putting the Repo into the supervise tree like so...

def init([]) do
  tree = [ worker(Repo, []) ]
  supervise(tree, strategy: :one_for_all)
end

They also recommend that start_link/0 function should not be called manually.

However, I found no convenient place to get this done in Weber. Am I missing something?

0xAX commented 10 years ago

Hello @AxisOfEval,

Weber has no supervisors, so you can create your own and put it to the your_project_name/lib directory, something like:

defmodule SimpleWeber.Sup do
  use Supervisor.Behaviour

  def start_link do
    :supervisor.start_link({ :local, __MODULE__ }, __MODULE__, [])
  end

  def init([]) do
    tree = [  worker(Repo, []) ]
    supervise(tree, strategy: :one_for_all)
  end
end

And put SimpleWeber.Sup.start_link after https://github.com/0xAX/weber/blob/master/templates/default/lib/app.ex#L11

AxisOfEval commented 10 years ago

Thanks a ton for this @0xAX :). I am going to try this today and revert...

AxisOfEval commented 10 years ago

Tried doing things like as you said, but ./start.sh bails out with the following message whenever I put in the Supervisor or the Repo's start_link in the last line of the start method in app.ex

All dependencies up to date
Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

lib/app.ex:9: warning: variable assigns is unused
lib/app.ex:9: warning: unused import Weber.Helper.Html
lib/app.ex:9: warning: unused import Weber.Helper.Partial
lib/app.ex:9: warning: unused import Weber.Helper.ResourceHelper
lib/app.ex:9: warning: unused import Weber.I18n
** (Mix) Could not start application KismetAPI, please see report above

Substituting the Supervisor's start_link/0 call with that of the Repo's gets the same result. However, if I type in Repo.start_link in the iex console it seems to work. Ditto for the supervisor, albeit with some missed messages. What am I doing wrong?

Also, is there a way getting a trace (or other details) of what mix ends up doing, and why exactly it bails?

AxisOfEval commented 10 years ago

I played around somewhat. Anywhere before Weber.run_weber seems to do the trick. If the line goes after that, then things compile fine but ./start.sh fails to launch.

0xAX commented 10 years ago

What's error after strart.sh?

0xAX commented 10 years ago

Ah sorry, missed your previous message. Which elixir version are you using? Did you enable logging?

AxisOfEval commented 10 years ago

I am using stuff pulled from the master branch. And yes, logging is enabled in lib/config.ex file. But nothing appears in the log files as start.sh bails out with the errors before lager/exlager can start...

If I start the supervisor before Weber.run_weber, things work OK. But I don't know if this is right.

rcdilorenzo commented 10 years ago

I know this is an old thread, so @AxisOfEval, is there anything we still need to address here?

AxisOfEval commented 10 years ago

I am not sure I remember exactly what's going on here to the minutiae, but I should be able to check code and revert over the weekend. Hope that's OK!

rcdilorenzo commented 10 years ago

Any update @AxisOfEval? I'm planning to close this issue if not.