What a journal does (Effect's EventJournal service).
Attributes#
| Attribute | Type | Description |
|---|---|---|
entries | Effect[list[Entry], EventJournalError] | Every entry, in id order. |
changes | Effect[Subscription[Entry], Never, Scope] | A subscription to the entries written locally. |
destroy | Effect[None, EventJournalError] | Remove every entry and every remote's progress. |
Functions#
entries_by_id#
entries_by_id(ids) -> Effect[list[Entry | None], EventJournalError]The entry of each id, None when unknown, in the ids' order.
| Parameter | Type | Description |
|---|---|---|
ids | Sequence[EntryId] |
Returns Effect[list[Entry | None], EventJournalError]
@abstractmethod
def entries_by_id(
self, ids: Sequence[EntryId], /
) -> Effect[list[Entry | None], EventJournalError]:
"""The entry of each id, ``None`` when unknown, in the ids' order."""write#
write[A, E, R](*, event, primary_key, payload, effect) -> Effect[A, EventJournalError | E, R]Write one entry, committed only when effect succeeds.
| Parameter | Type | Description |
|---|---|---|
event | str | |
primary_key | str | |
payload | bytes | |
effect | Callable[[Entry], Effect[A, E, R]] |
Returns Effect[A, EventJournalError | E, R]
def write[A, E, R](
self,
*,
event: str,
primary_key: str,
payload: bytes,
effect: Callable[[Entry], Effect[A, E, R]],
) -> Effect[A, EventJournalError | E, R]:
"""Write one entry, committed only when ``effect`` succeeds."""
return self.write_many(
[EntryInput(event, primary_key, payload)], lambda written: effect(written[0])
)write_many#
write_many[A, E, R](entries, effect) -> Effect[A, EventJournalError | E, R]Write the (non-empty) entries, committed only when
effect succeeds.
| Parameter | Type | Description |
|---|---|---|
entries | Sequence[EntryInput] | |
effect | Callable[[list[Entry]], Effect[A, E, R]] |
Returns Effect[A, EventJournalError | E, R]
@abstractmethod
def write_many[A, E, R](
self,
entries: Sequence[EntryInput],
effect: Callable[[list[Entry]], Effect[A, E, R]],
/,
) -> Effect[A, EventJournalError | E, R]:
"""Write the (non-empty) ``entries``, committed only when
``effect`` succeeds."""write_from_remote#
write_from_remote(*, remote_id, entries, effect, compact=None) -> Effect[list[Entry], EventJournalError]Import a remote's entries: the new ones (compacted by
compact) are replayed by effect in one batch with their
conflicts, then committed with the remote's sequence. Succeeds
with the entries that were already stored.
| Parameter | Type | Description |
|---|---|---|
remote_id | RemoteId | |
entries | Sequence[RemoteEntry] | |
effect | ReplayBatch | |
compact | Compact | None = None |
Returns Effect[list[Entry], EventJournalError]
@abstractmethod
def write_from_remote(
self,
*,
remote_id: RemoteId,
entries: Sequence[RemoteEntry],
effect: ReplayBatch,
compact: Compact | None = None,
) -> Effect[list[Entry], EventJournalError]:
"""Import a remote's entries: the new ones (compacted by
``compact``) are replayed by ``effect`` in one batch with their
conflicts, then committed with the remote's sequence. Succeeds
with the entries that were already stored."""with_remote_uncommitted#
with_remote_uncommitted[A, E, R](remote_id, f) -> Effect[Option[A], EventJournalError | E, R]Run f on the entries remote_id has not seen, if any; they
count as seen when it succeeds (Effect's withRemoteUncommited).
| Parameter | Type | Description |
|---|---|---|
remote_id | RemoteId | |
f | Callable[[list[Entry]], Effect[A, E, R]] |
Returns Effect[Option[A], EventJournalError | E, R]
@abstractmethod
def with_remote_uncommitted[A, E, R](
self, remote_id: RemoteId, f: Callable[[list[Entry]], Effect[A, E, R]], /
) -> Effect[Option[A], EventJournalError | E, R]:
"""Run ``f`` on the entries ``remote_id`` has not seen, if any; they
count as seen when it succeeds (Effect's ``withRemoteUncommited``)."""write_remote_acks#
write_remote_acks(*, remote_id, acks, first_sequence=None) -> Effect[None, EventJournalError]Record the sequences remote_id acknowledged.
| Parameter | Type | Description |
|---|---|---|
remote_id | RemoteId | |
acks | Sequence[RemoteAck] | |
first_sequence | int | None = None |
Returns Effect[None, EventJournalError]
@abstractmethod
def write_remote_acks(
self, *, remote_id: RemoteId, acks: Sequence[RemoteAck], first_sequence: int | None = None
) -> Effect[None, EventJournalError]:
"""Record the sequences ``remote_id`` acknowledged."""next_remote_sequence#
next_remote_sequence(remote_id) -> Effect[int, EventJournalError]The next sequence to read from remote_id.
| Parameter | Type | Description |
|---|---|---|
remote_id | RemoteId |
Returns Effect[int, EventJournalError]
@abstractmethod
def next_remote_sequence(self, remote_id: RemoteId, /) -> Effect[int, EventJournalError]:
"""The next sequence to read from ``remote_id``."""with_lock#
with_lock(store_id) -> WithLockRun an effect holding the lock of store_id.
| Parameter | Type | Description |
|---|---|---|
store_id | StoreId |
Returns WithLock
@abstractmethod
def with_lock(self, store_id: StoreId, /) -> WithLock:
"""Run an effect holding the lock of ``store_id``."""