manager

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 13 Imported by: 0

README

Transaction Manager

One Paragraph of the project description

Initially appeared on gist. But the page cannot open anymore so that is why I have moved it here.

Getting Started

These instructions will give you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on deploying the project on a live system.

Prerequisites

Requirements for the software and other tools to build, test and push

Installing

To use the library, you need to have go installed on your machine. You can install Go by following the instructions on the official website.

Once you have Go installed, you can install the library by running the following command

go get github.com/SimifiniiCTO/simfiny-core-lib/third-party/transaction-manager
Usage

To use the library, you must first initialize the client

import (
    txm "github.com/SimifiniiCTO/simfiny-core-lib/third-party/transaction-manager"
)

func main(){
    temporalOpts := &client.Options{
		HostPort:  "9999",
		Namespace: "test-namespace",
	}

    retryPolicy := &txm.Policy{
		RetryInitialInterval:    TemporalRetryInitialInterval,
		RetryBackoffCoefficient: TemporalBackoffCoefficient,
		MaximumInterval:         TemporalMaxRetryInterval,
		MaximumAttempts:         TemporalMaxRetryAttempts,
	}

    opts := []txm.Options{
        txm.WithClientOptions(temporalOpts),
        txm.WithInstrumentationClient(&instrumentation.Client{}),
        txm.WithLogger(log),
        txm.WithPostgres(postgresClient), // Optional 
        txm.WithMongo(mongoClient), // Optional
        txm.WithRetryPolicy(retryPolicy),
        txm.WithRpcTimeout(rpcTimeout),
        txm.WithMetricsEnabled(metricsEnabled)
        txm.WithMessageQueueClient(messageQueueClient) // Optional
    }

    txmClient, err := txm.New(opts...)
    if err != nil {
        ...
    }
}

Running the tests

Explain how to run the automated tests for this system

Sample Tests

Explain what these tests test and why

Give an example
Style test

Checks if the best practices and the right coding style has been used.

Give an example

Deployment

Add additional notes to deploy this on a live system

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use Semantic Versioning for versioning. For the versions available, see the tags on this repository.

Authors

  • Billie Thompson - Provided README Template - PurpleBooth

See also the list of contributors who participated in this project.

License

This project is licensed under the CC0 1.0 Universal Creative Commons License - see the LICENSE.md file for details

Acknowledgments

  • Hat tip to anyone whose code is used
  • Inspiration
  • etc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidClientOptions                = fmt.Errorf("invalid input argument. client options cannot be null")
	ErrInvalidTransactionManagerConfig     = fmt.Errorf("invalid input argument. transaction manager config cannot be nil")
	ErrInvalidLogger                       = fmt.Errorf("invalid logger. logger cannot be nil")
	ErrInvalidTelemetrySDK                 = fmt.Errorf("invalid telemetry sdk config. config cannot be nil")
	ErrNilAccount                          = fmt.Errorf("account cannot be nil")
	ErrNilOldEmail                         = fmt.Errorf("old email cannot be nil")
	ErrInvalidUpdateAccountWorkflowRequest = fmt.Errorf("invalid update account workflow request. request cannot be nil or invalid")
	ErrInvalidRetryPolicy                  = fmt.Errorf("invalid input argument. retry policy cannot be nil or invalid")
	ErrInvalidRpcTimeout                   = fmt.Errorf("invalid input argument. rpc timeout cannot be nil or invalid")
	ErrInvalidConfigurations               = fmt.Errorf("invalid input argument. transaction manager configurations cannot be nil or invalid")
)

Functions

func NewClient

func NewClient(opts *client.Options) (client.Client, error)

Instantiates a new client

func NewNamespaceClient

func NewNamespaceClient(opts *client.Options) (client.NamespaceClient, error)

NewNamespaceClient creates an instance of a namespace client, to manage lifecycle of namespaces.

func NewWorker

func NewWorker(client client.Client, taskQueue string, options worker.Options) worker.Worker

Instantiates a new worker

func WithClientOptions

func WithClientOptions(option *client.Options) func(*TransactionManager)

WithClientOptions defines the options to use when connecting to the database

func WithInstrumentationClient

func WithInstrumentationClient(telemetry *instrumentation.Client) func(*TransactionManager)

The function returns a function that takes a TransactionManager pointer and sets its instrumentation client to the provided one.

func WithLogger

func WithLogger(logger *zap.Logger) func(*TransactionManager)

The function returns a function that takes a TransactionManager pointer and sets its logger to the provided zap logger.

func WithMessageQueueClient

func WithMessageQueueClient(client *msq.Client) func(*TransactionManager)

This function returns a function that takes a TransactionManager pointer and sets its message queue client to the provided client.

func WithMetricsEnabled

func WithMetricsEnabled(enabled bool) func(*TransactionManager)

The function returns a function that takes a TransactionManager pointer and enables or disables metrics based on a boolean input.

func WithMongo

func WithMongo(mongoConn *mongo.Client) func(*TransactionManager)

The function returns a closure that takes a TransactionManager pointer and sets its mongoConn field to the provided mongo.Client pointer.

func WithPostgres

func WithPostgres(postgres *postgres.Client) func(*TransactionManager)

The function returns a function that takes a TransactionManager pointer and sets its Postgres client field to the provided client.

func WithRetryPolicy

func WithRetryPolicy(policy *Policy) func(*TransactionManager)

The function returns a function that takes a TransactionManager and sets its retry policy to the provided policy.

func WithRpcTimeout

func WithRpcTimeout(timeout time.Duration) func(*TransactionManager)

The function returns a function that takes a TransactionManager pointer and sets its RPC timeout to the specified duration.

Types

type Option

type Option = func(*TransactionManager)

Option is a function that takes a TransactionManager pointer and sets some option on it

type Policy

type Policy struct {
	RetryInitialInterval    *time.Duration
	RetryBackoffCoefficient float64
	MaximumInterval         time.Duration
	MaximumAttempts         int
}

Policy outlines retry policies necessary for workflow and downstream service calls

type TransactionManager

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

`TransactionManager` is the single struct by which we manage and initiate all distributed transactions within the service. It provides wrapper facilities around the temporal sdk client as well in order to properly emit metrics and traces during rpc operations

@property client - This is the client used to interact with a remote temporal cluster. @property TelemetrySDK - This is the telemetry SDK that we use to send telemetry data to newrelic @property Logger - This is the logger that will be used to log messages. @property AuthenticationServiceClient - This is the gRPC client for the Authentication Service. @property FinancialIntegrationServiceClient - This is the gRPC client for the Financial Integration Service. @property SocialServiceClient - This is the client for the Social Service. @property MessageQueueSDK - This is the message queue SDK that we will use to send messages to the queue. @property DatabaseConn - This is the database connection object that we will use to connect to the database.

func NewTransactionManager

func NewTransactionManager(options ...Option) (*TransactionManager, error)

It creates a new instance of the TransactionManager struct and returns it

func (*TransactionManager) Close

func (t *TransactionManager) Close()

Close closes the client and all its underlying connections and clears up any associated reasources

func (*TransactionManager) Start

func (tx *TransactionManager) Start()

Start enables the worker to start listening to a given task queue NOTE: This should be ran in a go routine otherwise the process will block

type WorkflowManager

type WorkflowManager interface {
	Close()
	Start()
}

Jump to

Keyboard shortcuts

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