I have the following code, and even though I can see (via the inspect) that the response_body does contain one of the strings I’m looking for, I’m not getting the “Waiting for Daemon to be ready message”?
Any ideas what I’m doing wrong please?
case HTTPoison.post(url, body, headers) do
{:ok, %{body: response_body}} →
IO.inspect(response_body)
if String.contains?(response_body, "Loading") ||
String.contains?(response_body, "Preparing databases") ||
String.contains?(response_body, "Rewinding") ||
String.contains?(response_body, "RPC server started") ||
String.contains?(response_body, "Verifying") do
Logger.info("Waiting for Daemon to be ready, attempt #{attempt}")
Process.sleep(3000)
{:cont, {:error, :wrong_response}}
I think you can figure out what’s happening easily if you try to open a Elixir interpreter with your application.
If it is a Phoenix app
iex -S mix phx.server
If not
iex -S mix
Then, you should be able to execute the Elixir Code from your function there, or you should be able to just copy paste an expression which you don’t know what should be the behavior.
You need to figure out whether it’s the contains check or the log statement that isn’t working. If you throw a raise "foo" in the if block that should narrow it down pretty quickly.
BTW, you would probably get better performance by writing a single regex for those terms and using Regex.match?/2 to do the check in one pass.
To add on to the above, make sure you check out the operators reference in the docs and click on any you’re curious about. One of the cool things about Elixir is that pretty much every language construct is implemented as a function or macro and they all have excellent docs.