Skip to content

Commit 6a18d3d

Browse files
committed
General refactor
1 parent 2b845fc commit 6a18d3d

File tree

18 files changed

+1700
-383
lines changed

18 files changed

+1700
-383
lines changed

Diff for: Makefile

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Variables
2+
PYTHONPATH := $(shell pwd)
3+
4+
linter: format
5+
poetry run bandit . && poetry run flake8 . && poetry run black --check .
6+
7+
format:
8+
poetry run isort . && poetry run black .
9+
10+
build:
11+
poetry build
12+
13+
install:
14+
poetry env use python3
15+
poetry lock
16+
poetry install
17+
18+
test: clean
19+
@PYTHONPATH="${PYTHONPATH}" ENVIRONMENT=unittest poetry run -vvv coverage run -vvv -m pytest
20+
21+
test-all:
22+
@PYTHONPATH="${PYTHONPATH}" ENVIRONMENT=local python -m pytest tests
23+
24+
update-poetry-and-all-dependencies:
25+
poetry self update
26+
poetry self add poetry-plugin-up
27+
poetry up --latest
28+
opentelemetry-bootstrap -a install
29+
30+
clean:
31+
@find . | egrep '.pyc|.pyo|pycache' | xargs rm -rf
32+
@find . | egrep '.pyc|.pyo|pycache|pytest_cache' | xargs rm -rf
33+
@rm -rf ./htmlcov
34+
@rm -rf ./pycache
35+
@rm -rf ./pycache
36+
@rm -rf ./.pytest_cache
37+
@rm -rf ./.mypy_cache
38+
@find . -name 'unit_test.db' -exec rm -r -f {} +
39+
@find . -name '.coverage' -exec rm -r -f {} +

Diff for: example/joe.py

+17-26
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,26 @@
22
Copyright 2022 Eigr.
33
Licensed under the Apache License, Version 2.0.
44
"""
5-
from dataclasses import dataclass
65
from domain.domain_pb2 import JoeState, Request, Reply
7-
from spawn.entity import ActorContext, ActorEntity, ActorInit, ActorParams, Value
86

7+
from spawn.eigr.functions.actors.api.actor import Actor
8+
from spawn.eigr.functions.actors.api.settings import ActorSettings
9+
from spawn.eigr.functions.actors.api.context import Context
10+
from spawn.eigr.functions.actors.api.metadata import Metadata
11+
from spawn.eigr.functions.actors.api.value import Value
12+
from spawn.eigr.functions.actors.api.workflows.broadcast import Broadcast
13+
from spawn.eigr.functions.actors.api.workflows.effect import Effect
914

10-
@dataclass
11-
class JoeActor(ActorInit):
1215

13-
# TODO: Remove this because it´s a bad design. Correct is extract this to superior Class
14-
def init() -> ActorParams:
15-
return ActorParams(
16-
name="joe",
17-
state_type=JoeState,
18-
snapshot_timeout=10000,
19-
deactivate_timeout=120000,
20-
)
16+
actor = Actor(settings=ActorSettings(name="joe", stateful=False))
2117

22-
entity = ActorEntity(init)
2318

24-
@entity.command("getActualState")
25-
def get_actual_state(self, ctx: ActorContext) -> Value:
26-
current_state = ctx.state
27-
new_value = current_state
28-
return Value(current_state, new_value)
29-
30-
@entity.command("setLanguage")
31-
def set_language(self, ctx: ActorContext) -> Value:
32-
reply = Reply()
33-
reply.response = "elf"
34-
35-
new_state = ctx.state.languages.extend("elf")
36-
return Value(new_state, reply)
19+
@actor.action("setLanguage")
20+
def set_language(request: Request, ctx: Context) -> Value:
21+
return Value()\
22+
.of("test")\
23+
.broadcast(Broadcast())\
24+
.effect(Effect())\
25+
.metada(Metadata())\
26+
.state({})\
27+
.reply()

Diff for: example/spawn_example.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
Licensed under the Apache License, Version 2.0.
44
"""
55
from spawn.eigr.functions.actors.api.sdk import Spawn
6-
from example.joe import JoeActor
6+
from example.joe import actor as joe_actor
77
from example.domain.domain_pb2 import Reply, Request
88

99
if __name__ == "__main__":
1010
request = Request()
1111
request.language = "erlang"
1212

1313
spawn = Spawn()
14-
spawn.port("8091").register_actor(JoeActor.entity).start()
15-
spawn.invoke("vijay", "setLanguage", request, Reply)
14+
spawn.port("9003").register_actor(joe_actor).start()
15+
# spawn.invoke("vijay", "setLanguage", request, Reply)

Diff for: poetry.lock

+1,225
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: protobuf/eigr/functions/protocol/actors/actor.proto

+23-23
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,27 @@ message TimeoutStrategy {
3838
int64 timeout = 1;
3939
}
4040

41-
// A command represents an action that the user can perform on an Actor.
42-
// Commands in supporting languages are represented by functions or methods.
43-
// An Actor command has nothing to do with the semantics of Commands in a CQRS/EventSourced system.
41+
// A action represents an action that the user can perform on an Actor.
42+
// Actions in supporting languages are represented by functions or methods.
43+
// An Actor action has nothing to do with the semantics of Actions in a CQRS/EventSourced system.
4444
// It just represents an action that supporting languages can invoke.
45-
message Command {
45+
message Action {
4646

4747
// The name of the function or method in the supporting language that has been registered in Ator.
4848
string name = 1;
4949
}
5050

51-
// A FixedTimerCommand is similar to a regular Command, its main differences are that it is scheduled to run at regular intervals
51+
// A FixedTimerAction is similar to a regular Action, its main differences are that it is scheduled to run at regular intervals
5252
// and only takes the actor's state as an argument.
53-
// Timer Commands are good for executing loops that manipulate the actor's own state.
53+
// Timer Actions are good for executing loops that manipulate the actor's own state.
5454
// In Elixir or other languages in BEAM it would be similar to invoking Process.send_after(self(), atom, msg, timeout)
55-
message FixedTimerCommand {
55+
message FixedTimerAction {
5656

57-
// The time to wait until the command is triggered
57+
// The time to wait until the action is triggered
5858
int32 seconds = 1;
5959

60-
// See Command description Above
61-
Command command = 2;
60+
// See Action description Above
61+
Action action = 2;
6262
}
6363

6464
message ActorState {
@@ -68,7 +68,7 @@ message ActorState {
6868

6969
// TODO doc here
7070
message Metadata {
71-
// A channel group represents a way to send commands to various actors
71+
// A channel group represents a way to send actions to various actors
7272
// that belong to a certain semantic group.
7373
string channel_group = 1;
7474

@@ -79,17 +79,17 @@ message Metadata {
7979
// Regardless of the type of actor it is important that
8080
// all actors are registered during the proxy and host initialization phase.
8181
enum Kind {
82-
// When no type is informed, the default to be assumed will be the Singleton pattern.
82+
// When no type is informed, the default to be assumed will be the Named pattern.
8383
UNKNOW_KIND = 0;
8484

85-
// Abstract actors are used to create children of this based actor at runtime
86-
ABSTRACT = 1;
85+
// NAMED actors are used to create children of this based actor at runtime
86+
NAMED = 1;
8787

88-
// Singleton actors as the name suggests have only one real instance of themselves running
89-
// during their entire lifecycle. That is, they are the opposite of the Abstract type Actors.
90-
SINGLETON = 2;
88+
// UNAMED actors as the name suggests have only one real instance of themselves running
89+
// during their entire lifecycle. That is, they are the opposite of the NAMED type Actors.
90+
UNAMED = 2;
9191

92-
// Pooled Actors are similar to abstract actors, but unlike them,
92+
// Pooled Actors are similar to Unamed actors, but unlike them,
9393
// their identifying name will always be the one registered at the system initialization stage.
9494
// The great advantage of Pooled actors is that they have multiple instances of themselves
9595
// acting as a request service pool.
@@ -134,7 +134,7 @@ message ActorId {
134134
// Name of a ActorSystem
135135
string system = 2;
136136

137-
// When the Actor is of the Abstract type,
137+
// When the Actor is of the Unamed type,
138138
// the name of the parent Actor must be informed here.
139139
string parent = 3;
140140
}
@@ -152,9 +152,9 @@ message Actor {
152152
// Actor settings.
153153
ActorSettings settings = 3;
154154

155-
// The commands registered for an actor
156-
repeated Command commands = 4;
155+
// The actions registered for an actor
156+
repeated Action actions = 4;
157157

158-
// The registered timer commands for an actor.
159-
repeated FixedTimerCommand timer_commands = 5;
158+
// The registered timer actions for an actor.
159+
repeated FixedTimerAction timer_actions = 5;
160160
}

Diff for: protobuf/eigr/functions/protocol/actors/protocol.proto

+29-22
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
//
5959
// Actors are usually created at the beginning of the SDK's communication flow with the Proxy by the registration step described above.
6060
// However, some use cases require that Actors can be created ***on the fly***.
61-
// In other words, Spawn is used to bring to life Actors previously registered as Abstracts, giving them a name and thus creating a concrete instance
61+
// In other words, Spawn is used to bring to life Actors previously registered as Unameds, giving them a name and thus creating a concrete instance
6262
// at runtime for that Actor. Actors created with the Spawn feature are generally used when you want to share a behavior while maintaining
6363
// the isolation characteristics of the actors.
6464
// For these situations we have the Spawning flow described below.
@@ -135,7 +135,7 @@
135135
// ║ ║ ║ ║
136136
// ║ ║ ╠───┐ ║
137137
// ║ ║ ║ │Handle request, ║
138-
// ║ ║ ║ │execute command
138+
// ║ ║ ║ │execute action
139139
// ║ ║ ║◀──┘ ║
140140
// ║ ║ ║ Reply with the ║
141141
// ║ ║ ╠────────────result and the ────────▶║
@@ -167,7 +167,8 @@ option go_package = "github.com/eigr/go-support/eigr/protocol;protocol";
167167
//
168168
// Params:
169169
// * state: Actor state passed back and forth between proxy and user function.
170-
// * metadata: Meta information or headers
170+
// * metadata: Meta information that comes in invocations
171+
// * tags: Meta information stored in the actor
171172
// * caller: ActorId of who is calling target actor
172173
// * self: ActorId of itself
173174
message Context {
@@ -176,6 +177,8 @@ message Context {
176177

177178
map<string, string> metadata = 4;
178179

180+
map<string, string> tags = 5;
181+
179182
// Who is calling target actor
180183
eigr.functions.protocol.actors.ActorId caller = 2;
181184

@@ -189,6 +192,12 @@ message Context {
189192
// he does not care about the input value only with the state.
190193
message Noop {}
191194

195+
// JSON is an alternative that some SDKs can opt in
196+
// it will bypass any type validation in spawn actors state / payloads
197+
message JSONType {
198+
string content = 1;
199+
}
200+
192201
message RegistrationRequest {
193202

194203
ServiceInfo service_info = 1;
@@ -268,8 +277,8 @@ message Broadcast {
268277
// Channel of target Actors
269278
string channel_group = 1;
270279

271-
// Command. Only Actors that have this command will run successfully
272-
string command_name = 2;
280+
// Action. Only Actors that have this action will run successfully
281+
string action_name = 2;
273282

274283
// Payload
275284
oneof payload {
@@ -278,26 +287,26 @@ message Broadcast {
278287
}
279288
}
280289

281-
// Sends the output of a command of an Actor to the input of another command of an Actor
290+
// Sends the output of a action of an Actor to the input of another action of an Actor
282291
// Useful for handle `pipes` pattern:
283292
// https://www.enterpriseintegrationpatterns.com/patterns/messaging/PipesAndFilters.html
284293
message Pipe {
285294
// Target Actor
286295
string actor = 1;
287296

288-
// Command.
289-
string command_name = 2;
297+
// Action.
298+
string action_name = 2;
290299
}
291300

292-
// Sends the input of a command of an Actor to the input of another command of an Actor
301+
// Sends the input of a action of an Actor to the input of another action of an Actor
293302
// Useful for handle `content-basead router` pattern
294303
// https://www.enterpriseintegrationpatterns.com/patterns/messaging/ContentBasedRouter.html
295304
message Forward {
296305
// Target Actor
297306
string actor = 1;
298307

299-
// Command.
300-
string command_name = 2;
308+
// Action.
309+
string action_name = 2;
301310
}
302311

303312
// Container for archicetural message patterns
@@ -316,22 +325,22 @@ message Workflow {
316325
// The user function when it wants to send a message to an Actor uses the InvocationRequest message type.
317326
//
318327
// Params:
319-
// * system: See ActorStstem message.
328+
// * system: See ActorSystem message.
320329
// * actor: The target Actor, i.e. the one that the user function is calling to perform some computation.
321330
// * caller: The caller Actor
322-
// * command_name: The function or method on the target Actor that will receive this request
331+
// * action_name: The function or method on the target Actor that will receive this request
323332
// and perform some useful computation with the sent data.
324-
// * value: This is the value sent by the user function to be computed by the request's target Actor command.
325-
// * async: Indicates whether the command should be processed synchronously, where a response should be sent back to the user function,
326-
// or whether the command should be processed asynchronously, i.e. no response sent to the caller and no waiting.
333+
// * value: This is the value sent by the user function to be computed by the request's target Actor action.
334+
// * async: Indicates whether the action should be processed synchronously, where a response should be sent back to the user function,
335+
// or whether the action should be processed asynchronously, i.e. no response sent to the caller and no waiting.
327336
// * metadata: Meta information or headers
328337
message InvocationRequest {
329338

330339
eigr.functions.protocol.actors.ActorSystem system = 1;
331340

332341
eigr.functions.protocol.actors.Actor actor = 2;
333342

334-
string command_name = 3;
343+
string action_name = 3;
335344

336345
oneof payload {
337346
google.protobuf.Any value = 4;
@@ -354,17 +363,17 @@ message InvocationRequest {
354363
//
355364
// Params:
356365
// * actor: The ActorId handling the InvocationRequest request, also called the target Actor.
357-
// * command_name: The function or method on the target Actor that will receive this request
366+
// * action_name: The function or method on the target Actor that will receive this request
358367
// and perform some useful computation with the sent data.
359368
// * current_context: The current Context with current state value of the target Actor.
360369
// That is, the same as found via matching in %Actor{name: target_actor, state: %ActorState{state: value} = actor_state}.
361370
// In this case, the Context type will contain in the value attribute the same `value` as the matching above.
362-
// * payload: The value to be passed to the function or method corresponding to command_name.
371+
// * payload: The value to be passed to the function or method corresponding to action_name.
363372
message ActorInvocation {
364373

365374
eigr.functions.protocol.actors.ActorId actor = 1;
366375

367-
string command_name = 2;
376+
string action_name = 2;
368377

369378
Context current_context = 3;
370379

@@ -439,5 +448,3 @@ message RequestStatus {
439448

440449
string message = 2;
441450
}
442-
443-

0 commit comments

Comments
 (0)