Skip to content
This repository was archived by the owner on Jun 11, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/event/listenable/flow.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,25 @@ defmodule Helix.Event.Listenable.Flow do
Expands the expected methods of the `Listenable` protocol.
"""
defmacro listen(event, do: block) do

fallback_block =
if elem(event, 0) == := do
quote do
def get_objects(_),
do: []
end
else
[]
end

quote do

@doc false
def get_objects(unquote(event)) do
unquote(block)
end

# Fallback
def get_objects(_),
do: []
unquote(fallback_block)

end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/event/loggable/flow.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Helix.Event.Loggable.Flow do
Top-level macro for events wanting to implement the Loggable protocol.
"""
defmacro loggable(do: block) do
quote do
quote generated: true do

defimpl Helix.Event.Loggable do
@moduledoc false
Expand Down
4 changes: 2 additions & 2 deletions lib/network/internal/bounce.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Helix.Network.Internal.Bounce do

with [bounce, sorted] = [%Bounce{}, %Bounce.Sorted{}] <- result do
bounce
|> Map.replace(:sorted, sorted)
|> Map.replace!(:sorted, sorted)
|> Bounce.format()
end
end
Expand Down Expand Up @@ -166,7 +166,7 @@ defmodule Helix.Network.Internal.Bounce do
{:ok, new_bounce} <- update_name_attempt
do
new_bounce
|> Map.replace(:sorted, new_sorted)
|> Map.replace!(:sorted, new_sorted)
|> Bounce.format()
else
_ ->
Expand Down
2 changes: 1 addition & 1 deletion lib/network/model/bounce.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ defmodule Helix.Network.Model.Bounce do
|> Map.put(:links, links)

# `sorted` is an implementation detail
|> Map.replace(:sorted, nil)
|> Map.replace!(:sorted, nil)

# See `File.format/1` for context
|> Ecto.put_meta(state: :loaded)
Expand Down
4 changes: 2 additions & 2 deletions lib/network/model/tunnel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ defmodule Helix.Network.Model.Tunnel do
t
def format(tunnel = %Tunnel{}) do
tunnel
|> Map.replace(:hops, get_hops(tunnel))
|> Map.replace(:bounce, format_bounce(tunnel))
|> Map.replace!(:hops, get_hops(tunnel))
|> Map.replace!(:bounce, format_bounce(tunnel))
end

@spec format_bounce(t) ::
Expand Down
10 changes: 5 additions & 5 deletions lib/process/model/process.ex
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ defmodule Helix.Process.Model.Process do
formatted_data = Processable.after_read_hook(process.data)

process
|> Map.replace(:state, get_state(process))
|> Map.replace(:data, formatted_data)
|> Map.replace!(:state, get_state(process))
|> Map.replace!(:data, formatted_data)
|> format_resources()
|> infer_usage()
|> estimate_duration()
Expand Down Expand Up @@ -575,9 +575,9 @@ defmodule Helix.Process.Model.Process do
end

process
|> Map.replace(:completion_date, completion_date)
|> Map.replace(:time_left, time_left)
|> Map.replace(:percentage, percentage)
|> Map.replace!(:completion_date, completion_date)
|> Map.replace!(:time_left, time_left)
|> Map.replace!(:percentage, percentage)
end

docp """
Expand Down
8 changes: 4 additions & 4 deletions lib/process/processable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Helix.Process.Processable do
Macro for implementation of the Processable protocol.
"""
defmacro processable(do: block) do
quote location: :keep do
quote location: :keep, generated: true do

defimpl Helix.Process.Model.Processable do

Expand Down Expand Up @@ -90,7 +90,7 @@ defmodule Helix.Process.Processable do
Default behaviour is to delete the process.
"""
defmacro on_kill(process, data, reason \\ quote(do: _), do: block) do
quote do
quote generated: true do

def kill(unquote(data), p = unquote(process), unquote(reason)) do
unquote(block)
Expand All @@ -108,7 +108,7 @@ defmodule Helix.Process.Processable do
Default behaviour is to send a SIGKILL to itself.
"""
defmacro on_source_connection_closed(process, data, connection, do: block) do
quote do
quote generated: true do

def source_connection_closed(
unquote(data),
Expand All @@ -130,7 +130,7 @@ defmodule Helix.Process.Processable do
Default behaviour is to send a SIGKILL to itself.
"""
defmacro on_target_connection_closed(process, data, connection, do: block) do
quote do
quote generated: true do

def target_connection_closed(
unquote(data),
Expand Down
2 changes: 1 addition & 1 deletion lib/process/resourceable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ defmodule Helix.Process.Resourceable do

# Fallbacks in case the user did not specify static and dynamic allocations
fallback_allocations =
quote do
quote generated: true do
@doc false
def static(_, _),
do: %{}
Expand Down
2 changes: 1 addition & 1 deletion lib/server/event/motherboard.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ defmodule Helix.Server.Event.Motherboard do
data =
event.index_cache
|> HardwareIndex.render_index()
|> Map.replace(:motherboard, nil)
|> Map.replace!(:motherboard, nil)

{:ok, data}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/server/internal/motherboard.ex
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ defmodule Helix.Server.Internal.Motherboard do
|> Enum.map(fn {component, _slot} -> component end)
|> Enum.zip(entries)
|> Enum.reduce([], fn {component, entry}, acc ->
entry = Map.replace(entry, :linked_component, component)
entry = Map.replace!(entry, :linked_component, component)

acc ++ [entry]
end)
Expand Down
6 changes: 3 additions & 3 deletions lib/server/model/motherboard.ex
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ defmodule Helix.Server.Model.Motherboard do
:ok ->
changeset
|> apply_changes()
|> Map.replace(:motherboard_id, mobo.component_id)
|> Map.replace!(:motherboard_id, mobo.component_id)

{:error, reason} ->
changeset
Expand Down Expand Up @@ -227,7 +227,7 @@ defmodule Helix.Server.Model.Motherboard do
:ok ->
changeset
|> apply_changes()
|> Map.replace(:motherboard_id, motherboard.motherboard_id)
|> Map.replace!(:motherboard_id, motherboard.motherboard_id)

{:error, reason} ->
changeset
Expand Down Expand Up @@ -258,7 +258,7 @@ defmodule Helix.Server.Model.Motherboard do
|> Map.delete(real_id)

acc
|> Map.replace(slot_type, new_sub_type)
|> Map.replace!(slot_type, new_sub_type)
end)

# Now we'll convert the available map into an API-friendly list
Expand Down
2 changes: 1 addition & 1 deletion lib/server/websocket/requests/config/check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ request Helix.Server.Websocket.Requests.Config.Check do
sub_request =
backend
|> apply(:new, [request.unsafe["value"], socket])
|> Map.replace(:relay, request.relay)
|> Map.replace!(:relay, request.relay)

with {:ok, sub_req} <- Requestable.check_params(sub_request, socket) do
update_meta(request, %{sub_request: sub_req}, reply: true)
Expand Down
2 changes: 1 addition & 1 deletion lib/server/websocket/requests/config/set.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ request Helix.Server.Websocket.Requests.Config.Set do
req =
backend
|> apply(:new, [req_params, socket])
|> Map.replace(:relay, request.relay)
|> Map.replace!(:relay, request.relay)

{key, req}
end)
Expand Down
2 changes: 1 addition & 1 deletion lib/software/model/file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule Helix.Software.Model.File do
end)

file
|> Map.replace(:modules, formatted_modules)
|> Map.replace!(:modules, formatted_modules)

# For some reason, Ecto assigns the `:built` state sometimes, which leads to
# some weird behaviour on some Repo inserts. As suggested here[1], we'll use
Expand Down
2 changes: 1 addition & 1 deletion lib/story/model/step/macros.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Helix.Story.Model.Step.Macros do
alias Helix.Story.Event.Step.ActionRequested, as: StepActionRequestedEvent

defmacro step(name, contact \\ nil, do: block) do
quote location: :keep do
quote location: :keep, generated: true do
defmodule unquote(name) do
@moduledoc false

Expand Down
2 changes: 1 addition & 1 deletion lib/websocket/request/proxy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule Helix.Websocket.Request.Proxy do
sub_request =
backend
|> apply(:new, [request.unsafe, socket])
|> Map.replace(:relay, request.relay)
|> Map.replace!(:relay, request.relay)

with {:ok, req} <- Requestable.check_params(sub_request, socket) do
update_meta(request, %{sub_request: req}, reply: true)
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ defmodule Helix.Mixfile do
{:ex_machina, "~> 2.1", only: :test},
{:earmark, "~> 1.2.4", only: :dev},
{:ex_doc, "~> 0.18.1", only: :dev},
{:dialyxir, "~> 0.5", only: [:dev], runtime: false},

{:inch_ex, "~> 0.5.6", only: [:dev, :test]},

Expand Down
3 changes: 2 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"credo": {:hex, :credo, "0.8.10", "261862bb7363247762e1063713bb85df2bbd84af8d8610d1272cd9c1943bba63", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, optional: false]}]},
"db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
"decimal": {:hex, :decimal, "1.4.1", "ad9e501edf7322f122f7fc151cce7c2a0c9ada96f2b0155b8a09a795c2029770", [:mix], []},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], []},
"distillery": {:hex, :distillery, "1.5.2", "eec18b2d37b55b0bcb670cf2bcf64228ed38ce8b046bb30a9b636a6f5a4c0080", [:mix], []},
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], []},
"ecto": {:hex, :ecto, "2.2.8", "a4463c0928b970f2cee722cd29aaac154e866a15882c5737e0038bbfcf03ec2c", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
Expand All @@ -36,7 +37,7 @@
"plug": {:hex, :plug, "1.4.5", "7b13869283fff6b8b21b84b8735326cc012c5eef8607095dc6ee24bd0a273d8e", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, optional: true]}, {:mime, "~> 1.0", [hex: :mime, optional: false]}]},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []},
"postgrex": {:hex, :postgrex, "0.13.4", "f58e319c5451bfda86ba6a45ce6dca311193d0a9861323d0d16e8d02e25adc41", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]},
"postgrex": {:hex, :postgrex, "0.13.5", "3d931aba29363e1443da167a4b12f06dcd171103c424de15e5f3fc2ba3e6d9c5", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]},
"ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], []},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []},
"timber": {:hex, :timber, "2.6.1", "946dee43730b30748c7a3ed0085abe8690dcbaf4cd96031caba676b938dd40a6", [:mix], [{:ecto, ">= 2.0.0 and < 2.3.0", [hex: :ecto, optional: true]}, {:hackney, "1.6.3 or 1.6.5 or 1.7.1 or 1.8.6 or ~> 1.9", [hex: :hackney, optional: false]}, {:msgpax, "~> 1.0", [hex: :msgpax, optional: false]}, {:phoenix, ">= 1.2.0 and < 1.4.0", [hex: :phoenix, optional: true]}, {:plug, ">= 1.2.0 and < 1.5.0", [hex: :plug, optional: true]}, {:poison, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :poison, optional: false]}]},
Expand Down
12 changes: 6 additions & 6 deletions test/process/event/handler/top_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ defmodule Helix.Process.Event.Handler.TOPTest do
{_, %{params: params}} =
ProcessSetup.fake_process(
gateway_id: server.server_id,
src_connection_id: connection.connection_id,
src_connection_id: connection.connection_id
)

params =
params
|> Map.replace(:data, FakeDefaultProcess.new())
|> Map.replace(:type, :fake_default_process)
|> Map.replace!(:data, FakeDefaultProcess.new())
|> Map.replace!(:type, :fake_default_process)

{:ok, process} = ProcessInternal.create(params)

Expand All @@ -54,13 +54,13 @@ defmodule Helix.Process.Event.Handler.TOPTest do
{_, %{params: params}} =
ProcessSetup.fake_process(
gateway_id: server.server_id,
tgt_connection_id: connection.connection_id,
tgt_connection_id: connection.connection_id
)

params =
params
|> Map.replace(:data, FakeDefaultProcess.new())
|> Map.replace(:type, :fake_default_process)
|> Map.replace!(:data, FakeDefaultProcess.new())
|> Map.replace!(:type, :fake_default_process)

{:ok, process} = ProcessInternal.create(params)

Expand Down
2 changes: 1 addition & 1 deletion test/process/model/process_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ defmodule Helix.Process.Model.ProcessTest do
l_limit: %{ram: 30},
r_limit: %{dlk: %{net: 20}},
l_reserved: %{cpu: 0, ram: 40, ulk: %{net: 30}, dlk: %{}},
r_reserved: %{cpu: 10, ram: 20, ulk: %{net: 15}, dlk: %{net: 20}},
r_reserved: %{cpu: 10, ram: 20, ulk: %{net: 15}, dlk: %{net: 20}}
)

process = Process.infer_usage(proc)
Expand Down
12 changes: 6 additions & 6 deletions test/process/model/top/allocator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ defmodule Helix.Process.Model.Top.AllocatorTest do
proc1 =
proc1
|> Map.from_struct()
|> Map.replace(:l_dynamic, [:cpu])
|> Map.replace!(:l_dynamic, [:cpu])
|> Map.put(:id, 1)
|> put_in([:static, :running, :ram], 0)
|> put_in([:static, :running, :ulk], 0)
Expand All @@ -68,7 +68,7 @@ defmodule Helix.Process.Model.Top.AllocatorTest do
proc2 =
proc2
|> Map.from_struct()
|> Map.replace(:l_dynamic, [:ram])
|> Map.replace!(:l_dynamic, [:ram])
|> Map.put(:id, 2)
|> put_in([:static, :running, :cpu], 0)
|> put_in([:static, :running, :ulk], 0)
Expand All @@ -78,7 +78,7 @@ defmodule Helix.Process.Model.Top.AllocatorTest do
proc3 =
proc3
|> Map.from_struct()
|> Map.replace(:l_dynamic, [:ulk])
|> Map.replace!(:l_dynamic, [:ulk])
|> Map.put(:id, 3)
|> put_in([:static, :running, :cpu], 0)
|> put_in([:static, :running, :ram], 0)
Expand All @@ -88,7 +88,7 @@ defmodule Helix.Process.Model.Top.AllocatorTest do
proc4 =
proc4
|> Map.from_struct()
|> Map.replace(:l_dynamic, [:dlk])
|> Map.replace!(:l_dynamic, [:dlk])
|> Map.put(:id, 4)
|> put_in([:static, :running, :cpu], 0)
|> put_in([:static, :running, :ram], 0)
Expand Down Expand Up @@ -222,8 +222,8 @@ defmodule Helix.Process.Model.Top.AllocatorTest do
total_resources
|> put_in([:dlk, :net], 0)
|> put_in([:ulk, :net], 0)
|> Map.replace(:cpu, proc.objective.cpu)
|> Map.replace(:ram, proc.objective.ram)
|> Map.replace!(:cpu, proc.objective.cpu)
|> Map.replace!(:ram, proc.objective.ram)

assert {:error, reason, _} =
TOPAllocator.allocate(:gateway, total_resources, [proc])
Expand Down
Loading