Skip to content

Commit

Permalink
non stateful actors fix and better macro handling for actions
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasdarruda committed Nov 26, 2024
1 parent 3da327e commit d2f66de
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/actors/actor/entity/entity.ex
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ defmodule Actors.Actor.Entity do
case action do
{:invocation_request, invocation, opts} ->
opts = Keyword.merge(opts, async: true)

handle_invocation_request(invocation, opts, nil, state)
|> reply_to_noreply()

Expand Down
10 changes: 8 additions & 2 deletions lib/actors/actor/entity/lifecycle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ defmodule Actors.Actor.Entity.Lifecycle do
{:ok, state, {:continue, :load_state}}
end

def load_state(%EntityState{actor: actor, revision: revision, opts: opts} = state) do
def load_state(
%EntityState{
actor: %Actor{settings: %ActorSettings{stateful: true}} = actor,
revision: revision,
opts: opts
} = state
) do
case get_state(actor.id, revision) do
{:ok, current_state, current_revision, status, node} ->
split_brain_detector =
Expand All @@ -122,7 +128,7 @@ defmodule Actors.Actor.Entity.Lifecycle do
{:continue, :call_init_action}}

error ->
handle_load_state_error(actor.name, state, error)
handle_load_state_error(actor.id, state, error)
end
end

Expand Down
16 changes: 14 additions & 2 deletions lib/spawn/cluster/provisioner/scheduler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ defmodule Spawn.Cluster.Provisioner.Scheduler do
The result of executing the provided function within the context of the actor provisioning system.
"""
def execute(
%SpawnTask{actor_name: actor_name, invocation: invocation, opts: opts, state: state, async: false},
%SpawnTask{
actor_name: actor_name,
invocation: invocation,
opts: opts,
state: state,
async: false
},
func
)
when is_function(func) do
Expand All @@ -42,7 +48,13 @@ defmodule Spawn.Cluster.Provisioner.Scheduler do
end

def execute(
%SpawnTask{actor_name: actor_name, invocation: invocation, opts: opts, state: state, async: true},
%SpawnTask{
actor_name: actor_name,
invocation: invocation,
opts: opts,
state: state,
async: true
},
func
)
when is_function(func) do
Expand Down
4 changes: 0 additions & 4 deletions spawn_sdk/spawn_sdk/lib/defact.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ defmodule SpawnSdk.Defact do
end

defmacro action(action_name, opts, block_fn) do
action_name = parse_action_name(action_name)

define_action(action_name, block_fn, opts)
end

defmacro action(action_name, block_fn) do
action_name = parse_action_name(action_name)

define_action(action_name, block_fn)
end

Expand Down

0 comments on commit d2f66de

Please sign in to comment.