core

package
v0.0.0-...-e677011 Latest Latest
Warning

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

Go to latest
Published: May 10, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ALPHA_VANTAGE_ENV_VAR_NAME     = "ALPHAVANTAGE_KEY"
	LOGS_PATH_ENV_VAR_NAME         = "SENTINEL_LOGS_PATH"
	NATS_STOCKS_VAR_NAME           = "NATS_STOCKS_DATA_URI"
	NATS_STOCKS_CLUSTERID_VAR_NAME = "NATS_STOCKS_CLUSTERID"
	DEFAULT_LOGS_PATH              = "./logs"
)
View Source
const (
	NATS_STOCKS_SUBJECT = "stocks"
)

Variables

View Source
var (
	ErrAlphaVantageKeyNotDefined        = errors.New("It was impossible to load AlphaVantageKey env var")
	ErrStocksNATSKeyNotDefined          = errors.New("It was impossible to load Stocks NATS URI env var")
	ErrStocksNATSClusterIDKeyNotDefined = errors.New("It was impossible to load Stocks NATS Cluster ID env var")
)

Functions

func LaunchSentinel

func LaunchSentinel(dockId string, context Context, schedule *Schedule) (err error)

LaunchSentinel creates and put a Sentinel to check stock price changes TODO remove mocked behaviour TODO add tests

Types

type AppContext

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

AppContext represents a general context for the application

func NewAppContext

func NewAppContext(config *SentinelConfig) (ctx *AppContext, err error)

NewAppContext knows how to instantiate Sentinels General Context TODO add some logging TODO add tests

func (*AppContext) Logger

func (ac *AppContext) Logger() *zap.Logger

Logger returns application default logger

func (*AppContext) SentinelConfig

func (ac *AppContext) SentinelConfig() *SentinelConfig

SentinelConfig returns Sentinel config

func (*AppContext) StockNats

func (ac *AppContext) StockNats() client.NATSServer

StockNats returns Nats server connection

type Context

type Context interface {
	SentinelConfig() *SentinelConfig
	StockNats() client.NATSServer
	Logger() *zap.Logger
}

type Dock

type Dock interface {
	GetId() string
	Watch() error
}

Dock represents a common interface to build all specific dock implementations

type Schedule

type Schedule struct {
	Stock     string
	TimeFrame string
}

func NewSchedule

func NewSchedule(stock string, timeFrame string) *Schedule

type Sentinel

type Sentinel interface {
	// Id returns an unique identifier to the sentinel
	Id() string

	// Run puts sentinel to run and returns its execution Id and an error
	Run(stockProvider client.StockProvider) (string, error)
}

type SentinelConfig

type SentinelConfig struct {
	AlphaVantageKey     string
	LogsPath            string
	NATSStocksURI       string
	NATSStocksClusterID string
}

SentinelConfig stores the general configuration directives for a Sentinel to run

func NewSentinelConfig

func NewSentinelConfig() (config *SentinelConfig, err error)

NewSentinelConfig creates an instance of Sentinel Config, loading all data necessary to run a Sentinel TODO add tests

type SentinelDock

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

SentinelDock knows when to launch new sentinels by watching a event stream

func NewSentinelDock

func NewSentinelDock(ctx Context) *SentinelDock

NewSentinelDock provides a working SentinelDock to a given app context TODO add tests

func (*SentinelDock) GetId

func (sd *SentinelDock) GetId() string

Id returns dock id (or execution id, if you prefer)

func (*SentinelDock) Watch

func (sd *SentinelDock) Watch() (err error)

Watch observes a queue in order to know when launch new Sentinels TODO add tests

type StockSentinel

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

func NewStockSentinel

func NewStockSentinel(ctx Context, schedule *Schedule) (sentinel *StockSentinel, err error)

NewSentinel is a base Sentinel build

func (*StockSentinel) Id

func (s *StockSentinel) Id() string

Id returns a unique identifier to the sentinel

func (*StockSentinel) Run

func (s *StockSentinel) Run(stockProvider client.StockProvider) (string, error)

Id returns a unique identifier to the sentinel

Jump to

Keyboard shortcuts

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