Eiji

Eiji

Hound does not work in mix task from normal console

The problem

In our scraping project we need to use hound (for only one scraper) and we want to run all scrapers in it at same time (by flow dependency). Only one scraper (that works in console) fails when running scraper. I created a smallest example to reproduce my problem.

Environment

Elixir and Erlang versions (both installed by asdf):

elixir -v
Erlang/OTP 19 [erts-8.3.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Elixir 1.4.2

Deps tree:

mix deps.tree
example
└── hound ~> 1.0 (Hex package)
    ├── hackney ~> 1.5 (Hex package)
    │   ├── certifi 1.2.1 (Hex package)
    │   ├── idna 5.0.2 (Hex package)
    │   │   └── unicode_util_compat 0.2.0 (Hex package)
    │   ├── metrics 1.0.1 (Hex package)
    │   ├── mimerl 1.0.2 (Hex package)
    │   └── ssl_verify_fun 1.1.1 (Hex package)
    └── poison >= 1.4.0 (Hex package)

Steps to reproduce:

1 create new project like: mix new example
2 add hound to dependencies and run mix deps.get
3 add to configuration: config :hound, driver: "phantomjs" (this is current configuration in our real project)
4 add mix task like:

defmodule Mix.Tasks.Example do
  use Mix.Task

  def run(_args) do
    Hound.start_session
    Hound.end_session
  end
end

5 run phantomjs with --wd argument
6 run example task like: mix example

Current behavior:

  1. Running elixir console for current project iex -S mix and running scraper Mix.Tasks.Example.run([]) works and returns :ok atom
  2. Running task like mix example raise:
** (ArgumentError) argument error
    (stdlib) :ets.lookup(Hound.SessionServer, #PID<0.71.0>)
    lib/hound/session_server.ex:19: Hound.SessionServer.current_session_id/1
    lib/hound/session_server.ex:13: Hound.SessionServer.session_for_pid/2
    lib/mix/tasks/example.ex:5: Mix.Tasks.Example.run/1
    (mix) lib/mix/task.ex:294: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2

Expected behavior:

In both cases (running task from iex and running task from normal console) should work and return :ok atom.

Am I forgot about something or it’s a bug in hound?

Marked As Solved

NobbZ

NobbZ

Your application is not started for tasks, if you need it started you have to do it yourself. iex -S mix does start your application, that’s why it works from there.

Also Liked

Eiji

Eiji

@NobbZ: Thank you :slight_smile:

It is always darkest before the dawn.

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement