dogmatiq / verity

🚧 An event-sourced Dogma engine.
MIT License
2 stars 2 forks source link

Add a `TransactionResult` type. #227

Closed jmalloc closed 4 years ago

jmalloc commented 4 years ago

The transaction result would be returned from Transaction.Commit() on success, and include the offset of the first event saved within this transaction, if any.

jmalloc commented 4 years ago

Rather than putting the offset in this new result type, we should place the same "item" slices (not the parcel slices) that appear in pipeline.Response, that will help with #210 and eventually those slices can be removed from pipeline.Response.

danilvpetrov commented 4 years ago

So generally the Transaction interface inside persistence pkg would look like the following (including the new TransactionResult type):

// Transaction exposes persistence operations that can be performed atomically.
// Transactions are not safe for concurrent use.
type Transaction interface {
    aggregatestore.Transaction
    eventstore.Transaction
    queuestore.Transaction
    offsetstore.Transaction

    // Commit applies the changes from the transaction.
    Commit(ctx context.Context) (TransactionResult, error)

    // Rollback aborts the transaction.
    Rollback() error
}

// TransactionResult is the result returned by Transaction.Commit() method.
type TransactionResult struct {
    EventItems []*eventstore.Item
    QueueItems []*queuestore.Item
}

Is this what you're thinking?

jmalloc commented 4 years ago

Yep, exactly!

danilvpetrov commented 4 years ago

Fixed by #235.