Skip to content

Commit 23eff31

Browse files
committed
Refactor configuration and improve message handling in the EngineSystem
- Added missing newlines at the end of several configuration files for consistency. - Updated the logging level in the test configuration from `:warn` to `:warning` for clarity. - Enhanced message handling in the EngineSystem by restructuring the message dispatching logic, improving readability and maintainability. - Simplified the diagram generation process by removing redundant error handling and streamlining the code in the DiagramGenerator module. These changes contribute to a cleaner codebase and better adherence to Elixir conventions.
1 parent 7fd9202 commit 23eff31

23 files changed

+574
-491
lines changed

config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ config :engine_system,
2222
# Import environment specific config
2323
if File.exists?("config/#{config_env()}.exs") do
2424
import_config "#{config_env()}.exs"
25-
end
25+
end

config/dev.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ config :logger,
77
# Development environment settings
88
config :engine_system,
99
generate_diagrams: false,
10-
diagram_output_dir: "docs/diagrams"
10+
diagram_output_dir: "docs/diagrams"

config/test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import Config
22

33
# Configure logger for tests
44
config :logger,
5-
level: :warn
5+
level: :warning
66

77
# Disable file generation during tests
88
config :engine_system,
99
compile_engines: false,
10-
generate_diagrams: false
10+
generate_diagrams: false

lib/engine_system/api.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule EngineSystem.API do
77

88
alias EngineSystem.Engine.{Spec, State}
99
alias EngineSystem.Lifecycle
10-
alias EngineSystem.System.{Registry, Services, Spawner}
10+
alias EngineSystem.System.{Message, Registry, Services, Spawner}
1111

1212
@doc """
1313
I start the EngineSystem application.
@@ -65,7 +65,7 @@ defmodule EngineSystem.API do
6565
# Use proper address format: {node_id, engine_id} where both are non_neg_integer
6666
# System address using proper format
6767
sender_addr = sender_address || {0, 0}
68-
message = EngineSystem.System.Message.new(sender_addr, target_address, message_payload)
68+
message = Message.new(sender_addr, target_address, message_payload)
6969

7070
# Use the Services.send_message function for actual sending
7171
Services.send_message(target_address, message)

lib/engine_system/engine.ex

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,36 @@ defmodule EngineSystem.Engine do
9393
def apply_filter(nil, _message), do: true
9494

9595
def apply_filter(filter, message) do
96-
filter.(message)
97-
rescue
98-
_ -> false
99-
catch
100-
_ -> false
96+
# Check function arity to determine how to call it
97+
info = :erlang.fun_info(filter, :arity)
98+
99+
case info do
100+
{:arity, 1} ->
101+
try do
102+
filter.(message)
103+
rescue
104+
_ -> false
105+
catch
106+
_ -> false
107+
end
108+
{:arity, 3} ->
109+
try do
110+
filter.(message, nil, nil)
111+
rescue
112+
_ -> false
113+
catch
114+
_ -> false
115+
end
116+
_ ->
117+
# Default to 1-arity for backward compatibility
118+
try do
119+
filter.(message)
120+
rescue
121+
_ -> false
122+
catch
123+
_ -> false
124+
end
125+
end
101126
end
102127

103128
# Private helper functions

0 commit comments

Comments
 (0)