Skip to content

Commit

Permalink
addressed dialyzer, verified hotwatch
Browse files Browse the repository at this point in the history
Signed-off-by: Brooks Townsend <brooks@cosmonic.com>
  • Loading branch information
brooksmtownsend committed May 5, 2023
1 parent e001d2f commit 76c4506
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
23 changes: 14 additions & 9 deletions wasmcloud_host/lib/wasmcloud_host/actor_watcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule WasmcloudHost.ActorWatcher do
GenServer.start_link(__MODULE__, args, name: :actor_watcher)
end

def hotwatch_actor(pid, path, replicas, host_id) do
GenServer.call(pid, {:hotwatch_actor, path, replicas, host_id}, 60_000)
def hotwatch_actor(pid, path, replicas, host_id, prefix) do
GenServer.call(pid, {:hotwatch_actor, path, replicas, host_id, prefix}, 60_000)
end

def stop_hotwatch(pid, actor_id) do
Expand Down Expand Up @@ -68,7 +68,7 @@ defmodule WasmcloudHost.ActorWatcher do
def handle_info({:reload_actor, path}, state) do
{:ok, bytes} = File.read(path)
actor_id = state |> Map.get(path, %{}) |> Map.get(:actor_id, "")
{local_host_id, _pid, _prefix} = WasmcloudHost.Application.first_host()
{local_host_id, _pid, prefix} = WasmcloudHost.Application.first_host()
existing_actors = ActorSupervisor.find_actor(actor_id, local_host_id)

replicas = existing_actors |> Enum.count()
Expand All @@ -80,15 +80,15 @@ defmodule WasmcloudHost.ActorWatcher do
%{}
)

start_actor(bytes, local_host_id, replicas)
start_actor(bytes, local_host_id, prefix, replicas)

new_actor = %{actor_id: actor_id, is_reloading: false}
{:noreply, Map.put(state, path, new_actor)}
end

def handle_call({:hotwatch_actor, path, replicas, host_id}, _from, state) do
def handle_call({:hotwatch_actor, path, replicas, host_id, prefix}, _from, state) do
with {:ok, bytes} <- File.read(path),
:ok <- start_actor(bytes, host_id, replicas),
:ok <- start_actor(bytes, host_id, prefix, replicas),
{:ok, claims} <- Native.extract_claims(bytes) do
if Map.get(state, path, nil) != nil do
# Already watching this actor, don't re-subscribe
Expand Down Expand Up @@ -125,10 +125,15 @@ defmodule WasmcloudHost.ActorWatcher do
end
end

@spec start_actor(bytes :: binary(), host_id :: binary(), replicas :: non_neg_integer()) ::
@spec start_actor(
bytes :: binary(),
host_id :: binary(),
prefix :: binary(),
replicas :: non_neg_integer()
) ::
:ok | {:error, any}
def start_actor(bytes, host_id, replicas) do
case ActorSupervisor.start_actor(bytes, host_id, "", replicas) do
def start_actor(bytes, host_id, prefix, replicas) do
case ActorSupervisor.start_actor(bytes, host_id, prefix, "", replicas) do
{:ok, _pids} -> :ok
{:error, e} -> {:error, e}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ defmodule StartActorComponent do
%{"count" => count},
socket
) do
{pk, _pid, _prefix} = WasmcloudHost.Application.first_host()
{pk, _pid, prefix} = WasmcloudHost.Application.first_host()

error_msg =
Phoenix.LiveView.consume_uploaded_entries(socket, :actor, fn %{path: path}, _entry ->
case File.read(path) do
{:ok, bytes} ->
ActorSupervisor.start_actor(bytes, pk, "", String.to_integer(count))
ActorSupervisor.start_actor(bytes, pk, prefix, "", String.to_integer(count))

{:error, reason} ->
{:error, "Error #{reason}"}
Expand All @@ -75,13 +75,14 @@ defmodule StartActorComponent do
%{"path" => path, "count" => count},
socket
) do
{host_id, _pid, _prefix} = WasmcloudHost.Application.first_host()
{host_id, _pid, prefix} = WasmcloudHost.Application.first_host()

case WasmcloudHost.ActorWatcher.hotwatch_actor(
:actor_watcher,
path,
String.to_integer(count),
host_id
host_id,
prefix
) do
:ok ->
Phoenix.PubSub.broadcast(WasmcloudHost.PubSub, "frontend", :hide_modal)
Expand Down

0 comments on commit 76c4506

Please sign in to comment.