Skip to content

store api at resonate lvl #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions resonate/resonate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from resonate.models.encoder import Encoder
from resonate.models.message_source import MessageSource
from resonate.models.retry_policy import RetryPolicy
from resonate.models.store import Store
from resonate.models.store import PromiseStore, Store


class Resonate:
Expand All @@ -57,10 +57,10 @@ def __init__(
self._registry = registry or Registry()
self._dependencies = dependencies or Dependencies()

self.store = store or LocalStore() if url is None else RemoteStore(url)
assert not isinstance(self.store, LocalStore) or message_source is None
self._store = store or LocalStore() if url is None else RemoteStore(url)
assert not isinstance(self._store, LocalStore) or message_source is None

message_source = message_source or self.store.as_msg_source() if isinstance(self.store, LocalStore) else Poller()
message_source = message_source or self._store.as_msg_source() if isinstance(self._store, LocalStore) else Poller()

# TODO(dfarr): grab default addresses from message source
self._unicast = unicast or f"poll://default/{self._pid}"
Expand All @@ -72,7 +72,7 @@ def __init__(
ttl=ttl,
anycast=self._anycast,
unicast=self._unicast,
store=self.store,
store=self._store,
message_source=message_source,
registry=self._registry,
)
Expand Down Expand Up @@ -209,6 +209,10 @@ def get(self, id: str) -> Handle[Any]:
def set_dependency(self, name: str, obj: Any) -> None:
self._dependencies.add(name, obj)

@property
def promises(self) -> PromiseStore:
return self._store.promises


# Context
class Context:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_hitl(resonate_instance: Resonate, id: str | None) -> None:
timestamp = int(time.time())
handle = resonate_instance.run(f"hitl-{timestamp}", hitl, id)
time.sleep(1)
resonate_instance.store.promises.resolve(id=id or f"hitl-{timestamp}.1", data=1)
resonate_instance.promises.resolve(id=id or f"hitl-{timestamp}.1", data=1)
assert handle.result() == 1


Expand Down
Loading