trigger

package
v2.2.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2018 License: Apache-2.0 Imports: 5 Imported by: 32

Documentation

Overview

Package trigger provides interface for trigger plugins. A trigger plugin has to implement the following function. - NewTrigger(config map[string]interface{}) (Trigger, error)

The trigger instance returned by this function will be called on Fire() with the filePath (relative to root directory) and indexes that have been written (appended or updated). It is guaranteed that the new content has been written on disk when Fire() is called, so it is safe to read it from disk. Keep in mind that the trigger might be called on the startup, due to the WAL recovery.

Triggers can be configured in the marketstore config file.

triggers:
  - module: xxxTrigger.so
    on: "*/1Min/OHLCV"
    config: <according to the plugin>

The "on" value is matched with the file path to decide whether the trigger is fired or not. It can contain wildcard character "*". As of now, trigger fires only on the running state. Trigger on WAL replay may be added later.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecordsToColumnSeries

func RecordsToColumnSeries(
	tbk io.TimeBucketKey,
	ds []io.DataShape,
	ca *io.CandleAttributes,
	tf time.Duration,
	year int16,
	records []Record) *io.ColumnSeries

RecordsToColumnSeries takes a slice of Record, along with the required information for constructing a ColumnSeries, and builds it from the slice of Record.

Types

type Record

type Record []byte

Record represents a serialized byte buffer for a record written to the DB

func ColumnSeriesToRecords

func ColumnSeriesToRecords(tbk io.TimeBucketKey, cs io.ColumnSeries) ([]Record, error)

ColumnSeriesToRecords takes a TimeBucketKey and a ColumnSeries and converts them to a slice of trigger.Record

func (*Record) Bytes

func (r *Record) Bytes() []byte

Bytes returns the raw record buffer

func (*Record) Index

func (r *Record) Index() int64

Index returns the index of the record

func (*Record) Payload

func (r *Record) Payload() []byte

Payload returns the data payload of the record, excluding the index

type SymbolLoader

type SymbolLoader interface {
	LoadSymbol(symbolName string) (interface{}, error)
}

SymbolLoader is an interface to retrieve symbol object from plugin

type Trigger

type Trigger interface {
	// Fire is called when the target file has been modified.
	// keyPath is the string path of the modified file relative
	// from the catalog root directory.  indexes is a slice
	// containing indexes of the rows being modified.
	Fire(keyPath string, records []Record)
}

Trigger is an interface every trigger plugin has to implement.

func Load

func Load(loader SymbolLoader, config map[string]interface{}) (Trigger, error)

Load loads a function named NewTrigger with a parameter type map[string]interface{} and initialize the trigger.

type TriggerMatcher

type TriggerMatcher struct {
	Trigger Trigger
	// On is a string representing the condition of the trigger
	// fire event.  It is the prefix of file path such as
	// ""*/1Min/OHLC"
	On string
}

TriggerMatcher checks if the trigger should be fired or not.

func NewMatcher

func NewMatcher(trigger Trigger, on string) *TriggerMatcher

NewMatcher creates a new TriggerMatcher.

func (*TriggerMatcher) Match

func (tm *TriggerMatcher) Match(keyPath string) bool

Match returns true if keyPath matches the On condition.

Jump to

Keyboard shortcuts

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