-
-
Notifications
You must be signed in to change notification settings - Fork 66
fix: properly log when engine fails to initialize #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4e099f7
dc9c8f1
fe14474
e381804
b879ac1
d168107
d71cc76
5ae550e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,13 +5,16 @@ defmodule Expert.EngineNode do | |
| use Expert.Project.Progress.Support | ||
|
|
||
| defmodule State do | ||
| require Logger | ||
|
|
||
| defstruct [ | ||
| :project, | ||
| :port, | ||
| :cookie, | ||
| :stopped_by, | ||
| :stop_timeout, | ||
| :started_by, | ||
| :last_message, | ||
| :status | ||
| ] | ||
|
|
||
|
|
@@ -47,9 +50,14 @@ defmodule Expert.EngineNode do | |
| # If we start distribution manually after all the code is loaded, | ||
| # everything works fine. | ||
| """ | ||
| {:ok, _} = Node.start(:"#{Project.node_name(state.project)}", :longnames) | ||
| #{Forge.NodePortMapper}.register() | ||
| IO.puts(\"ok\") | ||
| node_start = Node.start(:"#{Project.node_name(state.project)}", :longnames) | ||
| case node_start do | ||
| {:ok, _} -> | ||
| #{Forge.NodePortMapper}.register() | ||
| IO.puts(\"ok\") | ||
| {:error, reason} -> | ||
| IO.puts(\"error starting node:\n \#{inspect(reason)}\") | ||
| end | ||
| """ | ||
| | path_append_arguments(paths) | ||
| ] | ||
|
|
@@ -103,6 +111,28 @@ defmodule Expert.EngineNode do | |
| end | ||
| end | ||
|
|
||
| def on_exit_status(%__MODULE__{} = state, exit_status) do | ||
| stop_reason = | ||
| case exit_status do | ||
| 0 -> | ||
| project = state.project | ||
| Logger.info("Engine for #{project.root_uri} shut down") | ||
|
|
||
| :shutdown | ||
|
|
||
| _error_status -> | ||
| Logger.error( | ||
| "Engine shut down unexpectedly, node exited with status #{exit_status}). Last message: #{state.last_message}" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the root_uri here as well and any other log about the engine
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the project as a prefix but I'm not sure that's desired in the current incarnation. Let me know if this message format looks good to you. |
||
| ) | ||
|
|
||
| {:shutdown, {:node_exit, %{status: exit_status, last_message: state.last_message}}} | ||
| end | ||
|
|
||
| new_state = %{state | status: :stopped} | ||
|
|
||
| {stop_reason, new_state} | ||
| end | ||
|
|
||
| def maybe_reply_to_stopper(%State{stopped_by: stopped_by} = state) | ||
| when is_tuple(stopped_by) do | ||
| GenServer.reply(state.stopped_by, :ok) | ||
|
|
@@ -373,9 +403,18 @@ defmodule Expert.EngineNode do | |
| end | ||
|
|
||
| @impl true | ||
| def handle_info({_port, {:data, message}}, %State{} = state) do | ||
| Logger.debug("Node port message: #{to_string(message)}") | ||
| {:noreply, state} | ||
| def handle_info({_port, {:exit_status, exit_status}}, %State{} = state) do | ||
| {stop_reason, state} = State.on_exit_status(state, exit_status) | ||
|
|
||
| {:stop, stop_reason, state} | ||
| end | ||
|
|
||
| @impl true | ||
| def handle_info({_port, {:data, data}}, %State{} = state) do | ||
| message = to_string(data) | ||
| Logger.debug("Node port message: #{message}") | ||
|
|
||
| {:noreply, %{state | last_message: message}} | ||
| end | ||
|
|
||
| @impl true | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.