datastore

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package datastore maintains all the datastorage implementation.

Package datastore contains datastore implementation for outbox.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoEvents = errors.New("no events")

ErrNoEvents is an error returned when no ready outbox rows available after mining from DB.

Functions

This section is empty.

Types

type MineSweeper

type MineSweeper interface {
	// Mine mines the ready to dispatch outbox rows from DB.
	// Implementor should marks the fetched rows Status to InProcess so as to avoid being same records re-fetched in another
	// iteration by Worker.
	Mine(ctx context.Context) ([]event.OutboxRow, error)

	// Sweep delete or mark as Failed on publish occur or fails respectively.
	Sweep(context.Context, []int, []int) error
	io.Closer
}

MineSweeper should be implemented by Datastore.

func NewMySQL

func NewMySQL(db *sql.DB, table string, logger *zap.Logger) (MineSweeper, error)

NewMySQL constructs MySQL with all dependencies.

func NewPostgres

func NewPostgres(db *sql.DB, table string, logger *zap.Logger) (MineSweeper, error)

NewPostgres constructs Postgres with all dependencies.

type MySQL

type MySQL struct {
	// contains filtered or unexported fields
}

MySQL represents mysql implementation for MineSweeper.

func (MySQL) Close

func (p MySQL) Close() error

Close closes the MySQL DB connection.

func (MySQL) Mine

func (p MySQL) Mine(ctx context.Context) (outboxRows []event.OutboxRow, err error)

Mine fetches and returns all the outbox rows which are ready to publish(having Status IS NULL).

Marks the fetched rows Status to InProcess so as to avoid same records being re-fetched in another iteration by Worker.

func (MySQL) Sweep

func (p MySQL) Sweep(ctx context.Context, dispatchedIDs, failedIDs []int) error

Sweep deletes the dispatched outbox rows when successfully published. otherwise marks those records as Failed when failed to publish.

It should be called by Messaging system.

type Postgres

type Postgres struct {
	// contains filtered or unexported fields
}

Postgres represents postgres implementation for MineSweeper.

func (Postgres) Close

func (p Postgres) Close() error

Close closes the Postgres DB connection.

func (Postgres) Mine

func (p Postgres) Mine(ctx context.Context) ([]event.OutboxRow, error)

Mine fetches and returns all the outbox rows which are ready to publish(having Status IS NULL).

Marks the fetched rows Status to InProcess so as to avoid same records being re-fetched in another iteration by Worker.

func (Postgres) Sweep

func (p Postgres) Sweep(ctx context.Context, relayedIDs []int, failedIDs []int) error

Sweep deletes the dispatched outbox rows when successfully published. otherwise marks those records as Failed when failed to publish.

It should be called by Messaging system.

type Status

type Status int

Status represents the outbox row status.

const (
	// InProcess represents outbox row is already being processed by worker.
	InProcess Status = iota + 1

	// Failed represents failed to publish outbox row.
	Failed
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL