Skip to content

Commit e92f7a9

Browse files
committed
Attach invocation
1 parent 9bae76a commit e92f7a9

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

python/restate/context.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ def cancel(self, invocation_id: str):
228228
Cancels the invocation with the given id.
229229
"""
230230

231+
@abc.abstractmethod
232+
def attach_invocation(self, invocation_id: str, serde: Serde[T] = JsonSerde()) -> T:
233+
"""
234+
Attaches the invocation with the given id.
235+
"""
236+
231237

232238
class ObjectContext(Context, KeyValueStore):
233239
"""

python/restate/server_context.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,18 @@ def cancel(self, invocation_id: str):
436436
if invocation_id is None:
437437
raise ValueError("invocation_id cannot be None")
438438
self.vm.sys_cancel(invocation_id)
439+
440+
def attach_invocation(self, invocation_id: str, serde: Serde[T] = JsonSerde()) -> T:
441+
if invocation_id is None:
442+
raise ValueError("invocation_id cannot be None")
443+
assert serde is not None
444+
handle = self.vm.attach_invocation(invocation_id)
445+
coro = self.create_poll_or_cancel_coroutine(handle)
446+
447+
async def await_point():
448+
"""Wait for this handle to be resolved."""
449+
res = await coro
450+
assert res is not None
451+
return serde.deserialize(res)
452+
453+
return await_point()

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,17 @@ impl PyVM {
658658
.map_err(Into::into)
659659
}
660660

661+
fn attach_invocation(
662+
mut self_: PyRefMut<'_, Self>,
663+
invocation_id: String,
664+
) -> Result<PyNotificationHandle, PyVMError> {
665+
self_
666+
.vm
667+
.sys_attach_invocation(restate_sdk_shared_core::AttachInvocationTarget::InvocationId(invocation_id))
668+
.map(Into::into)
669+
.map_err(Into::into)
670+
}
671+
661672
fn sys_end(mut self_: PyRefMut<'_, Self>) -> Result<(), PyVMError> {
662673
self_.vm.sys_end().map(Into::into).map_err(Into::into)
663674
}

0 commit comments

Comments
 (0)