How to use the eventsourcing.exceptions.RecordConflictError function in eventsourcing

To help you get started, we’ve selected a few eventsourcing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github johnbywater / eventsourcing / eventsourcing / infrastructure / popo / manager.py View on Github external
try:
            application_records = self._all_sequence_records[self.application_name]
        except KeyError:
            sequence_records = {}
            application_records = {sequence_id: sequence_records}
            self._all_sequence_records[self.application_name] = application_records
            self._all_sequence_max[self.application_name] = {}
        else:
            try:
                sequence_records = application_records[sequence_id]
            except KeyError:
                sequence_records = {}
                application_records[sequence_id] = sequence_records

        if position in sequence_records:
            raise RecordConflictError(position, len(sequence_records))

        if self.notification_id_name:
            # Just make sure we aren't making a gap in the sequence.
            if sequence_records:
                max_position = self._all_sequence_max[self.application_name][
                    sequence_id
                ]
                next_position = max_position + 1
            else:
                next_position = 0
            if position != next_position:
                raise AssertionError(
                    "Next position for sequence {} is {}, not {}".format(
                        sequence_id, next_position, position
                    )
                )
github johnbywater / eventsourcing / eventsourcing / infrastructure / popo / manager.py View on Github external
app_tracking_records = {}
                    self._all_tracking_records[
                        self.application_name
                    ] = app_tracking_records
                try:
                    upstream_tracking_records = app_tracking_records[
                        upstream_application_name
                    ]
                except KeyError:
                    upstream_tracking_records = set()
                    app_tracking_records[
                        upstream_application_name
                    ] = upstream_tracking_records

                if notification_id in upstream_tracking_records:
                    raise RecordConflictError(
                        (application_name, upstream_application_name, notification_id)
                    )
                upstream_tracking_records.add(notification_id)
github johnbywater / eventsourcing / eventsourcing / infrastructure / base.py View on Github external
def raise_record_integrity_error(self, e: Exception) -> None:
        raise RecordConflictError(e)
github johnbywater / eventsourcing / eventsourcing / exceptions.py View on Github external
"""Raised when unable to resolve a topic to a Python class."""


class EntityVersionNotFound(EventSourcingError):
    """Raise when accessing an entity version that does not exist."""


class RecordConflictError(EventSourcingError):
    """Raised when database raises an integrity error."""


class PromptFailed(EventSourcingError):
    """Raised when prompt fails."""


class ConcurrencyError(RecordConflictError):
    """Raised when a record conflict is due to concurrency."""


class ConsistencyError(EventSourcingError):
    """Raised when applying an event stream to a versioned entity."""


class MismatchedOriginatorError(ConsistencyError):
    """Raised when applying an event to an inappropriate object."""


class OriginatorIDError(MismatchedOriginatorError):
    """Raised when applying an event to the wrong entity or aggregate."""


class OriginatorVersionError(MismatchedOriginatorError):
github johnbywater / eventsourcing / eventsourcing / application / actors.py View on Github external
def run_process(self, msg):
        notification_count = 0
        # Just process one notification so prompts are dispatched promptly, sent
        # messages only dispatched from actor after receive_message() returns.
        advance_by = 1

        try:
            if msg.last_prompts:
                for prompt in msg.last_prompts.values():
                    notification_count += self.process.run(
                        prompt, advance_by=advance_by
                    )
            else:
                notification_count += self.process.run(advance_by=advance_by)
        except RecordConflictError:
            # Run again.
            self.send(
                self.myAddress, SlaveRunRequest(last_prompts={}, master=msg.master)
            )
        else:
            if notification_count:
                # Run again, until nothing was done.
                self.send(
                    self.myAddress, SlaveRunRequest(last_prompts={}, master=msg.master)
                )
            else:
                # Report back to master.
                self.send(msg.master, SlaveRunResponse())
github johnbywater / eventsourcing / eventsourcing / infrastructure / base.py View on Github external
def raise_sequenced_item_conflict(self) -> None:
        msg = "Position already taken in sequence"
        raise RecordConflictError(msg)