gor

package
v0.0.1-20230330-0002 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const ErrCodeAlreadyRunning = 100
View Source
const ErrCodeFailedToSetDefaultValuesForConfig = 104
View Source
const ErrCodeOnRunIsNotAFunction = 103
View Source
const ErrCodeReRunOnRecoverMaxNrOfPanicsIsLowerThanOne = 105
View Source
const ErrCodeRunFunctionAlreadyRunning = 106
View Source
const ErrCodeRunTimeIsZero = 101
View Source
const ErrCodeRunTimesIsLowerThanOne = 102
View Source
const ErrCodeStopFunctionAlreadyRunning = 107

Variables

View Source
var ErrAlreadyRunning = define.Err(ErrCodeAlreadyRunning, "already running...")
View Source
var ErrFailedToSetDefaultValuesForConfig = define.Err(ErrCodeFailedToSetDefaultValuesForConfig, "failed to set default values for config")
View Source
var ErrOnRunIsNotAFunction = define.Err(ErrCodeOnRunIsNotAFunction, "'OnRun' if not a function")
View Source
var ErrReRunOnRecoverMaxNrOfPanicsIsLowerThanOne = define.Err(ErrCodeReRunOnRecoverMaxNrOfPanicsIsLowerThanOne, "'rerun on recover max nr of panics' times is lower than -1")
View Source
var ErrRunFunctionAlreadyRunning = define.Err(ErrCodeRunFunctionAlreadyRunning, "Run function already running...")
View Source
var ErrRunTimeIsZero = define.Err(ErrCodeRunTimeIsZero, "'run times' is 0")
View Source
var ErrRunTimesIsLowerThanOne = define.Err(ErrCodeRunTimesIsLowerThanOne, "'run times' is lower than -1")
View Source
var ErrStopFunctionAlreadyRunning = define.Err(ErrCodeStopFunctionAlreadyRunning, "Stop function already running...")

Functions

This section is empty.

Types

type Config

type Config struct {
	// Logger
	Logger *model.Logger

	OnRun func(instance *GInstance)
	// AutoRecover -> from panic!
	// It's a boolean
	AutoRecover interface{} `yaml:"auto_recover" mapstructure:"auto_recover" default:"yes"`
	// If the function OnRun had a panic, and it AutoRecovered, should it rerun itself again?!
	// If setting no, it will not rerun itself,
	// If Setting yes, it will rerun itself,
	// but be very carefully, it can run infinitely if you have infinite panics!
	// It's a boolean
	ReRunOnRecover interface{} `yaml:"rerun_on_recover" mapstructure:"rerun_on_recover" default:"no"`
	// This is the recovery options related to ReRunOnRecover
	ReRunOnRecoverOptions ReRunOnRecoverOptions `yaml:"rerun_on_recover_options" mapstructure:"rerun_on_recover_options"`

	// Add how many times it should run! default it's 1, -1 it's infinite, any number of times!
	RunTimes int `yaml:"run_times" mapstructure:"run_times" default:"1"`
	// AutoRun -> It's a Boolean, Should it run on creation!?
	AutoRun interface{} `yaml:"auto_run" mapstructure:"auto_run" default:"yes"`
	// when the execution finished!
	OnRunFinished func(instance *GInstance)

	OnExiting func(instance *GInstance)
	// OnAllFinished -> when everything has being finished as planned
	OnAllFinished func(instance *GInstance)
}

Config -> options

type GInstance

type GInstance struct {

	// Logger
	Logger *model.Logger
	// contains filtered or unexported fields
}

func GO

func GO(ctx context.Context, config Config) (*GInstance, error)

GO -> run a goroutine

func (*GInstance) GetContext

func (g *GInstance) GetContext() context.Context

func (*GInstance) IsRunning

func (g *GInstance) IsRunning() bool

func (*GInstance) IsTerminating

func (g *GInstance) IsTerminating() bool

IsTerminating -> usually it's necessary for the callback, to know if the goroutines it's being declared to terminate or the parents!

func (*GInstance) LDebug

func (g *GInstance) LDebug() *zerolog.Event

LDebug -> 0

func (*GInstance) LDebugF

func (g *GInstance) LDebugF(functionName string) *zerolog.Event

LDebugF -> when you need specifically to indicate in what function the logging is happening

func (*GInstance) LError

func (g *GInstance) LError() *zerolog.Event

LError -> 3

func (*GInstance) LErrorF

func (g *GInstance) LErrorF(functionName string) *zerolog.Event

LErrorF -> when you need specifically to indicate in what function the logging is happening

func (*GInstance) LEvent

func (g *GInstance) LEvent(eventType string, eventName string, beforeMsg func(event *zerolog.Event))

func (*GInstance) LEventCustom

func (g *GInstance) LEventCustom(eventType string, eventName string) *zerolog.Event

func (*GInstance) LEventF

func (g *GInstance) LEventF(eventType string, eventName string, functionName string) *zerolog.Event

func (*GInstance) LFatal

func (g *GInstance) LFatal() *zerolog.Event

LFatal -> 4

func (*GInstance) LInfo

func (g *GInstance) LInfo() *zerolog.Event

LInfo -> 1

func (*GInstance) LInfoF

func (g *GInstance) LInfoF(functionName string) *zerolog.Event

LInfoF -> when you need specifically to indicate in what function the logging is happening

func (*GInstance) LPanic

func (g *GInstance) LPanic() *zerolog.Event

LPanic -> 5

func (*GInstance) LWarn

func (g *GInstance) LWarn() *zerolog.Event

LWarn -> 2

func (*GInstance) LWarnF

func (g *GInstance) LWarnF(functionName string) *zerolog.Event

LWarnF -> when you need specifically to indicate in what function the logging is happening

func (*GInstance) Run

func (g *GInstance) Run() error

Run -> start the goroutine

func (*GInstance) Stop

func (g *GInstance) Stop() error

type ReRunOnRecoverOptions

type ReRunOnRecoverOptions struct {
	// After how much time it should run again after recovery! Duration it's measured in nanoseconds -> 100000000 = 100 ms or 0.1 seconds
	RunAfterDuration time.Duration `yaml:"run_after_duration" mapstructure:"run_after_duration" default:"100000000"`
	// How many panics it should be allowed to happen... -1 is infinite!
	MaxNrOfPanics int `yaml:"max_nr_of_panics" mapstructure:"max_nr_of_panics" default:"-1"`
}

Jump to

Keyboard shortcuts

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