interceptor

package
v0.0.0-...-4abf3d4 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetricCronPerformance = "cron_performance"
)

Variables

This section is empty.

Functions

func DefaultKV

func DefaultKV(method string, err error) map[string]string

DefaultKV returns a standardized service tracking.

func DefaultWorkerPool

func DefaultWorkerPool() cronx.Interceptor

DefaultWorkerPool returns a WorkerPool middleware with default configuration.

func DistributedLock

func DistributedLock(
	serviceName string,
	mode string,
	dl DistributedLockItf,
	sc SlackClientItf,
) cronx.Interceptor

DistributedLock is a middleware that prevents a process executed at the same time across servers.

func Logger

func Logger() cronx.Interceptor

Logger is a middleware that logs the current job start and finish.

func NotifySlack

func NotifySlack(
	serviceName string,
	mode string,
	sc SlackClientItf,
) cronx.Interceptor

NotifySlack is a middleware that send alert to slack on error.

func Recover

func Recover() cronx.Interceptor

Recover is a middleware that recovers server from panic. Recover also dumps stack trace on panic occurrence.

func RecoverWithAlert

func RecoverWithAlert(
	serviceName string,
	mode string,
	sc SlackClientItf,
) cronx.Interceptor

RecoverWithAlert is a middleware that recovers server from panic. On panic occurrence, we will dump the stack trace and send alert to Slack.

func RequestID

func RequestID(
	ctx context.Context,
	job *cronx.Job,
	handler cronx.Handler,
) error

RequestID is a middleware that inject request id to the context if it doesn't exist.

func Telemetry

func Telemetry(metric TelemetryClientItf) cronx.Interceptor

Telemetry is a middleware that push the latency of a process.

func WorkerPool

func WorkerPool(size int) cronx.Interceptor

WorkerPool is a middleware that limit total cron that can run a time. Program is running on a server with finite amount of resources such as CPU and RAM. By limiting the total number of jobs that can be run the same time, we protect the server from overloading.

Types

type DistributedLockItf

type DistributedLockItf interface {
	Mutex(name string) *redsync.Mutex
}

type SlackClientItf

type SlackClientItf interface {
	Send(ctx context.Context, msg string, mention bool)
}

type TelemetryClientItf

type TelemetryClientItf interface {
	Histogram(metricName string, value float64, tags map[string]string)
}

Jump to

Keyboard shortcuts

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