Documentation
¶
Index ¶
- Constants
- Variables
- func AnnotateTracerProvider(base oteltrace.TracerProvider) oteltrace.TracerProvider
- func AsCronJob(j any, expression string, options ...gocron.JobOption) fx.Option
- func Contains(list []string, item string) bool
- func CtxCronJobExecutionId(ctx context.Context) string
- func CtxCronJobName(ctx context.Context) string
- func CtxLogger(ctx context.Context) *log.Logger
- func CtxTracer(ctx context.Context) oteltrace.Tracer
- func GetReturnType(target any) string
- func GetType(target any) string
- func NewFxCron(p FxCronParam) (gocron.Scheduler, error)
- func Sanitize(str string) string
- func Split(str string) []string
- type CronJob
- type CronJobDefinition
- type CronJobMetrics
- func (m *CronJobMetrics) IncrementCronJobExecutionError(jobName string) *CronJobMetrics
- func (m *CronJobMetrics) IncrementCronJobExecutionSuccess(jobName string) *CronJobMetrics
- func (m *CronJobMetrics) ObserveCronJobExecutionDuration(jobName string, jobDuration float64) *CronJobMetrics
- func (m *CronJobMetrics) Register(registry *prometheus.Registry) error
- type CronJobRegistry
- type CronSchedulerFactory
- type CtxCronJobExecutionIdKey
- type CtxCronJobNameKey
- type DefaultCronSchedulerFactory
- type FxCronJobRegistryParam
- type FxCronModuleInfo
- type FxCronParam
- type ResolvedCronJob
- type TracerProviderCronJobAnnotator
- func (a *TracerProviderCronJobAnnotator) ForceFlush(context.Context) error
- func (a *TracerProviderCronJobAnnotator) OnEnd(otelsdktrace.ReadOnlySpan)
- func (a *TracerProviderCronJobAnnotator) OnStart(ctx context.Context, s otelsdktrace.ReadWriteSpan)
- func (a *TracerProviderCronJobAnnotator) Shutdown(context.Context) error
Constants ¶
const ( EXECUTION_SUCCESS = "success" EXECUTION_ERROR = "error" )
const ( ModuleName = "cron" LogRecordFieldCronJobName = "cronJob" LogRecordFieldCronJobExecutionId = "cronJobExecutionID" TraceSpanAttributeCronJobName = "CronJob" TraceSpanAttributeCronJobExecutionId = "CronJobExecutionID" )
const NON_AVAILABLE = "n/a"
Variables ¶
var FxCronModule = fx.Module( ModuleName, fx.Provide( NewDefaultCronSchedulerFactory, NewFxCronJobRegistry, NewFxCron, fx.Annotate( NewFxCronModuleInfo, fx.As(new(interface{})), fx.ResultTags(`group:"core-module-infos"`), ), ), )
FxCronModule is the Fx cron module.
Functions ¶
func AnnotateTracerProvider ¶
func AnnotateTracerProvider(base oteltrace.TracerProvider) oteltrace.TracerProvider
AnnotateTracerProvider extends a provided oteltrace.TracerProvider spans with cron jobs execution attributes.
func AsCronJob ¶
AsCronJob registers a cron job into Fx, with an optional list of gocron.JobOption.
func CtxCronJobExecutionId ¶
CtxCronJobExecutionId returns the contextual cron job execution id.
func CtxCronJobName ¶
CtxCronJobName returns the contextual cron job name.
func GetReturnType ¶
GetReturnType returns the return type of a target.
func NewFxCron ¶
func NewFxCron(p FxCronParam) (gocron.Scheduler, error)
NewFxCron returns a new gocron.Scheduler.
Types ¶
type CronJobDefinition ¶
type CronJobDefinition interface { ReturnType() string Expression() string Options() []gocron.JobOption }
CronJobDefinition is the interface for cron job definitions.
func NewCronJobDefinition ¶
func NewCronJobDefinition(returnType string, expression string, options ...gocron.JobOption) CronJobDefinition
NewCronJobDefinition returns a new CronJobDefinition.
type CronJobMetrics ¶
type CronJobMetrics struct {
// contains filtered or unexported fields
}
CronJobMetrics is the metrics handler for the cron jobs.
func NewCronJobMetrics ¶
func NewCronJobMetrics(namespace string, subsystem string) *CronJobMetrics
NewCronJobMetrics returns a new CronJobMetrics instance for provided metrics namespace and subsystem.
func NewCronJobMetricsWithBuckets ¶
func NewCronJobMetricsWithBuckets(namespace string, subsystem string, buckets []float64) *CronJobMetrics
NewCronJobMetricsWithBuckets returns a new CronJobMetrics instance for provided metrics namespace, subsystem and buckets.
func (*CronJobMetrics) IncrementCronJobExecutionError ¶
func (m *CronJobMetrics) IncrementCronJobExecutionError(jobName string) *CronJobMetrics
IncrementCronJobExecutionError increments the number of execution errors for a given cron job.
func (*CronJobMetrics) IncrementCronJobExecutionSuccess ¶
func (m *CronJobMetrics) IncrementCronJobExecutionSuccess(jobName string) *CronJobMetrics
IncrementCronJobExecutionSuccess increments the number of execution successes for a given cron job.
func (*CronJobMetrics) ObserveCronJobExecutionDuration ¶
func (m *CronJobMetrics) ObserveCronJobExecutionDuration(jobName string, jobDuration float64) *CronJobMetrics
ObserveCronJobExecutionDuration observes the duration of a cron job execution.
func (*CronJobMetrics) Register ¶
func (m *CronJobMetrics) Register(registry *prometheus.Registry) error
Register allows the CronJobMetrics to register against a provided prometheus.Registry.
type CronJobRegistry ¶
type CronJobRegistry struct {
// contains filtered or unexported fields
}
CronJobRegistry is the registry collecting cron jobs and their definitions.
func NewFxCronJobRegistry ¶
func NewFxCronJobRegistry(p FxCronJobRegistryParam) *CronJobRegistry
NewFxCronJobRegistry returns as new CronJobRegistry.
func (*CronJobRegistry) ResolveCronJobs ¶
func (r *CronJobRegistry) ResolveCronJobs() ([]*ResolvedCronJob, error)
ResolveCronJobs resolves a list of ResolvedCronJob from their definitions.
type CronSchedulerFactory ¶
type CronSchedulerFactory interface {
Create(options ...gocron.SchedulerOption) (gocron.Scheduler, error)
}
CronSchedulerFactory is the interface for gocron.Scheduler factories.
func NewDefaultCronSchedulerFactory ¶
func NewDefaultCronSchedulerFactory() CronSchedulerFactory
NewDefaultCronSchedulerFactory returns a DefaultCronSchedulerFactory, implementing CronSchedulerFactory.
type CtxCronJobExecutionIdKey ¶
type CtxCronJobExecutionIdKey struct{}
CtxCronJobExecutionIdKey is a contextual struct key.
type CtxCronJobNameKey ¶
type CtxCronJobNameKey struct{}
CtxCronJobNameKey is a contextual struct key.
type DefaultCronSchedulerFactory ¶
type DefaultCronSchedulerFactory struct{}
DefaultCronSchedulerFactory is the default CronSchedulerFactory implementation.
func (*DefaultCronSchedulerFactory) Create ¶
func (f *DefaultCronSchedulerFactory) Create(options ...gocron.SchedulerOption) (gocron.Scheduler, error)
Create returns a new gocron.Scheduler instance for an optional list of gocron.SchedulerOption.
type FxCronJobRegistryParam ¶
type FxCronJobRegistryParam struct { fx.In CronJobs []CronJob `group:"cron-jobs"` CronJobsDefinitions []CronJobDefinition `group:"cron-jobs-definitions"` }
FxCronJobRegistryParam allows injection of the required dependencies in NewFxCronJobRegistry.
type FxCronModuleInfo ¶
type FxCronModuleInfo struct {
// contains filtered or unexported fields
}
FxCronModuleInfo is a module info collector for fxcore.
func NewFxCronModuleInfo ¶
func NewFxCronModuleInfo(scheduler gocron.Scheduler, registry *CronJobRegistry) *FxCronModuleInfo
NewFxCronModuleInfo returns a new FxCronModuleInfo.
func (*FxCronModuleInfo) Data ¶
func (i *FxCronModuleInfo) Data() map[string]interface{}
Data return the data of the module info.
func (*FxCronModuleInfo) Name ¶
func (i *FxCronModuleInfo) Name() string
Name return the name of the module info.
type FxCronParam ¶
type FxCronParam struct { fx.In LifeCycle fx.Lifecycle Generator uuid.UuidGenerator TracerProvider oteltrace.TracerProvider Factory CronSchedulerFactory Config *config.Config Registry *CronJobRegistry Logger *log.Logger MetricsRegistry *prometheus.Registry }
FxCronParam allows injection of the required dependencies in NewFxCron.
type ResolvedCronJob ¶
type ResolvedCronJob struct {
// contains filtered or unexported fields
}
ResolvedCronJob represents a resolved cron job, with its expression and execution options.
func NewResolvedCronJob ¶
func NewResolvedCronJob(implementation CronJob, expression string, options ...gocron.JobOption) *ResolvedCronJob
NewResolvedCronJob returns a new ResolvedCronJob instance.
func (*ResolvedCronJob) Expression ¶
func (r *ResolvedCronJob) Expression() string
Expression returns the ResolvedCronJob cron job expression.
func (*ResolvedCronJob) Implementation ¶
func (r *ResolvedCronJob) Implementation() CronJob
Implementation returns the ResolvedCronJob cron job implementation.
func (*ResolvedCronJob) Options ¶
func (r *ResolvedCronJob) Options() []gocron.JobOption
Options returns the ResolvedCronJob cron job execution options.
type TracerProviderCronJobAnnotator ¶
type TracerProviderCronJobAnnotator struct{}
TracerProviderCronJobAnnotator is the oteltrace.TracerProvider cron jobs annotator, implementing otelsdktrace.SpanProcessor.
func NewTracerProviderCronJobAnnotator ¶
func NewTracerProviderCronJobAnnotator() *TracerProviderCronJobAnnotator
NewTracerProviderCronJobAnnotator returns a new [TracerProviderWorkerAnnotator].
func (*TracerProviderCronJobAnnotator) ForceFlush ¶
func (a *TracerProviderCronJobAnnotator) ForceFlush(context.Context) error
ForceFlush is just for otelsdktrace.SpanProcessor compliance.
func (*TracerProviderCronJobAnnotator) OnEnd ¶
func (a *TracerProviderCronJobAnnotator) OnEnd(otelsdktrace.ReadOnlySpan)
OnEnd is just for otelsdktrace.SpanProcessor compliance.
func (*TracerProviderCronJobAnnotator) OnStart ¶
func (a *TracerProviderCronJobAnnotator) OnStart(ctx context.Context, s otelsdktrace.ReadWriteSpan)
OnStart adds cron job execution attributes to a given otelsdktrace.ReadWriteSpan.
func (*TracerProviderCronJobAnnotator) Shutdown ¶
func (a *TracerProviderCronJobAnnotator) Shutdown(context.Context) error
Shutdown is just for otelsdktrace.SpanProcessor compliance.