GitHub

EventLogService

API reference for EventLogService.

What an event log does (Effect's EventLog service).

Attributes

AttributeTypeDescription
entries= entries
destroy= destroy
synced= synced

Succeeds once every registered remote has acknowledged the entries written so far and the log has applied the remote's changes up to the latest it stored when asked (a pyfect addition). A remote that cannot tell its latest sequence is only uploaded to. Fails with EventLogDestroyedError once destroy has run on this log; a journal destroyed directly, not through the log, is not noticed.

Functions

__init__

__init__(write_events, entries, destroy, synced, compact) -> None
ParameterTypeDescription
write_eventsCallable[[Sequence[tuple[str, object]]], Effect[list[object], object]]
entriesEffect[list[Entry], EventJournalError]
destroyEffect[None, EventJournalError]
syncedEffect[None, EventJournalError | EventLogRemoteError | EventLogDestroyedError]
compactCallable[[RemoteId | None], Effect[list[CompactOutcome], EventJournalError | EventLogRemoteError]]
def __init__(
    self,
    write_events: Callable[[Sequence[tuple[str, object]]], Effect[list[object], object]],
    entries: Effect[list[Entry], EventJournalError],
    destroy: Effect[None, EventJournalError],
    synced: Effect[None, EventJournalError | EventLogRemoteError | EventLogDestroyedError],
    compact: Callable[
        [RemoteId | None], Effect[list[CompactOutcome], EventJournalError | EventLogRemoteError]
    ],
) -> None:
    self._write_events = write_events
    self._compact = compact
    self.entries = entries
    self.destroy = destroy
    self.synced = synced
    """Succeeds once every registered remote has acknowledged the
    entries written so far and the log has applied the remote's
    changes up to the latest it stored when asked (a pyfect addition).
    A remote that cannot tell its latest sequence is only uploaded to. Fails
    with ``EventLogDestroyedError`` once ``destroy`` has run on this log; a
    journal destroyed directly, not through the log, is not noticed."""

compact

compact(*, remote_id=None) -> Effect[list[CompactOutcome], EventJournalError | EventLogRemoteError]

Run one remote compaction now, on every registered remote that offers compaction or only on remote_id. Unlike the background trigger it does not wait for the journal to catch up, and it works from an empty journal. Remotes built with compaction=False are skipped, and nothing runs when no compactor is registered with remote=True. See CompactResult for the results.

ParameterTypeDescription
remote_idRemoteId | None = None

Returns Effect[list[CompactOutcome], EventJournalError | EventLogRemoteError]

def compact(
    self, *, remote_id: RemoteId | None = None
) -> Effect[list[CompactOutcome], EventJournalError | EventLogRemoteError]:
    """Run one remote compaction now, on every registered remote that
    offers compaction or only on ``remote_id``. Unlike the background
    trigger it does not wait for the journal to catch up, and it works
    from an empty journal. Remotes built with ``compaction=False`` are
    skipped, and nothing runs when no compactor is registered with
    ``remote=True``. See ``CompactResult`` for the results."""
    return self._compact(remote_id)

write

write[P, A, E](event: Event[P, A, E], payload: P, /) -> Effect[A, E | EventJournalError]
write(event: str, payload: object, /) -> Effect[object, object]

Write event with payload and run its handler, succeeding with its result.

ParameterTypeDescription
event
payload
@overload
def write[P, A, E](
    self, event: Event[P, A, E], payload: P, /
) -> Effect[A, E | EventJournalError]: ...
@overload
def write(self, event: str, payload: object, /) -> Effect[object, object]: ...
def write(self, event: AnyEvent | str, payload: object, /) -> Effect[object, object]:
    """Write ``event`` with ``payload`` and run its handler, succeeding
    with its result."""
    tag = event if isinstance(event, str) else event.tag
    return self._write_events([(tag, payload)]).map(lambda results: results[0])

write_many

write_many[A, E](writes) -> Effect[list[A], E | EventJournalError]

Write the (non-empty) writes under one lock and handler transaction, succeeding with their results in order.

ParameterTypeDescription
writesSequence[AnyWrite[A, E]]

Returns Effect[list[A], E | EventJournalError]

def write_many[A, E](
    self, writes: Sequence[AnyWrite[A, E]], /
) -> Effect[list[A], E | EventJournalError]:
    """Write the (non-empty) ``writes`` under one lock and handler
    transaction, succeeding with their results in order."""
    # Each Write ties its payload to its event; the handlers give A or E.
    written = self._write_events([(w.event.tag, w.payload) for w in writes])
    return cast("Effect[list[A], E | EventJournalError]", written)