benjamintanweihao / the-little-elixir-otp-guidebook-code

Code examples for The Little Elixir & OTP Guidebook
372 stars 71 forks source link

Chapter 8 - Blitzy implementation is different from the repo? #3

Open sashaafm opened 8 years ago

sashaafm commented 8 years ago

Hello, Blitzy's implementation from the book seems different from the repo. The version in the book has a start/2 function because Blitzy.Caller passes its PID in order to get the results back to it.

Which version is the correct one? Maybe the chapter 8 in the book still hasn't been finalized?

Thanks

zeroasterisk commented 7 years ago

I agree - I am looking at the example code, and it looks like much of it is written into the cli file, whereas the book has most of these functions implemented inside.

I've been trying, but I still can't get this working correctly: https://github.com/zeroasterisk/blitzy

iex(alan@alan-MBP)1> Blitzy.do_requests(10, "https://www.google.com", [:"alan@alan-MBP"])
Pummelling https://www.google.com with 10 requests from #PID<0.190.0>

23:37:52.354 [info]  Pummelling https://www.google.com with 10 requests from #PID<0.190.0>
** (exit) exited in: GenServer.call({TasksSupervisor, :"alan@alan-MBP"}, {:start_child, [#PID<0.190.0>, :monitor, {:"alan@alan-MBP", #PID<0.190.0>}, {Blitzy.Worker, :start, ["https://www.google.com", #PID<0.190.0>]}]}, :infinity)
    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
    (elixir) lib/gen_server.ex:729: GenServer.call/3
    (elixir) lib/task/supervisor.ex:255: Task.Supervisor.do_async/5
    (elixir) lib/enum.ex:1233: anonymous fn/3 in Enum.map/2
    (elixir) lib/enum.ex:1785: Enum.reduce_range_inc/4
    (elixir) lib/enum.ex:1760: Enum.map/2
    (elixir) lib/enum.ex:966: Enum.flat_map_list/2
    (blitzy) lib/blitzy.ex:18: Blitzy.do_requests/3
ziazek commented 7 years ago

@zeroasterisk try adding alias Blitzy.TasksSupervisor in blitzy/lib/blitzy.ex

Exegetech commented 7 years ago

@ziazek I am also experiencing the same problem with @zeroasterisk . Tried the alias and it still doesn't work.

tat2133 commented 7 years ago

@zeroasterisk @christiansakai You all may have figured this out by now, but for posterity's sake: this error pops up for me whenever I forget to include the app itself in mix.exs (so it is started at runtime). You have to make sure that you have

def application do
  mod: {Blitzy, []},
  # extra_applications, etc
end

in mix.exs

eboCode commented 5 years ago

Adding the alias (from @ziazek) still gives me the error/stack trace @zeroasterisk posted above. Also, isn't what @tat2133 suggests already in the mix.exs code in the book, as well as on the book's GitHub site for the source code?

Anyone solved this yet?