Skip to content

Commit

Permalink
Use new spawn protocol version
Browse files Browse the repository at this point in the history
  • Loading branch information
sleipnir committed Aug 26, 2023
1 parent 892f687 commit 1b4be2b
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 57 deletions.
2 changes: 2 additions & 0 deletions protobuf/eigr/functions/protocol/actors/protocol.proto
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ message ActorInvocationResponse {
}

Workflow workflow = 5;

bool checkpoint = 7;
}

// InvocationResponse is the response that the proxy that received the InvocationRequest request will forward to the request's original user function.
Expand Down
28 changes: 28 additions & 0 deletions protobuf/eigr/functions/protocol/actors/state.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// The Spawn State Extension Protocol
//
//
syntax = "proto3";

package eigr.functions.protocol.state;

import "eigr/functions/protocol/actors/actor.proto";

option java_package = "io.eigr.functions.protocol.state";
option go_package = "github.com/eigr/go-support/eigr/protocol/state;state";

// A revision is just a version number for a record in the snapshot table that stores the actors' state.
// When an actor has its snaphost timeout, it increments its internal revision number and saves it along with its internal data.
// Some of the persistence adapters can use this revision number to find the state of an Actor at a given point in time.
// As Actors in Spawn persist their internal data as snapshots from time to time a revision number may not indicate the state of a given change
// but will most likely point to the exact time that a given actor's internal state was persisted into the database.
message Revision {
int64 value = 1;
}

// A checkpoint encapsulates a revision and the state it represents.
message Checkpoint {

Revision revision = 1;

eigr.functions.protocol.actors.ActorState state = 2;
}
5 changes: 3 additions & 2 deletions scripts/compile-pb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ set -o errexit
set -o pipefail

# follow the basic steps here: https://grpc.io/docs/tutorials/basic/python/
#protoc -I ../protobuf/ --python_out=../spawn eigr/functions/protocol/actors/actor.proto
#protoc -I ../protobuf/ --python_out=../spawn eigr/functions/protocol/actors/protocol.proto
protoc -I ../protobuf/ --python_out=../spawn eigr/functions/protocol/actors/actor.proto
protoc -I ../protobuf/ --python_out=../spawn eigr/functions/protocol/actors/protocol.proto
protoc -I ../protobuf/ --python_out=../spawn eigr/functions/protocol/actors/state.proto

protoc -I ../example/protobuf/ --python_out=../example ../example/protobuf/domain/domain.proto
10 changes: 8 additions & 2 deletions spawn/eigr/functions/actors/api/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Value():
__forward: Forward = None
__pipe: Pipe = None
__reply_kind: ReplyKind = ReplyKind.REPLY
__checkpoint: bool = False

def get_state(self):
return self.__state
Expand Down Expand Up @@ -55,6 +56,9 @@ def get_pipe(self):
def get_reply_kind(self):
return self.__reply_kind

def has_checkpoint(self):
return self.__checkpoint

def of(self, value, state=None):
self.__response = value
self.__state = state
Expand Down Expand Up @@ -96,10 +100,12 @@ def pipe(self, pipe: Pipe):
self.__pipe = pipe
return self

def reply(self):
def reply(self, checkpoint: bool = False):
self.__reply_kind = ReplyKind.REPLY
self.__checkpoint = checkpoint
return self

def noreply(self):
def noreply(self, checkpoint: bool = False):
self.__reply_kind = ReplyKind.NO_REPLY
self.__checkpoint = checkpoint
return self
3 changes: 3 additions & 0 deletions spawn/eigr/functions/actors/internal/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def handle_response(system, actor_name, result):
pipe.action_name = p.action
actor_invocation_response.workflow.pipe.CopyFrom(pipe)

if result.has_checkpoint():
actor_invocation_response.checkpoint = True

return actor_invocation_response


Expand Down
90 changes: 45 additions & 45 deletions spawn/eigr/functions/protocol/actors/actor_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1b4be2b

Please sign in to comment.