job

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: MIT Imports: 7 Imported by: 0

README

Job

Job Types

  • All jobs must conform to the Basic job interface.
  • All jobs must be registered in the JobRegistry.
  • All jobs must have an associated Producer which defines the routine that is responsible for adding new jobs to the queue.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Basic

type Basic interface {
	RegistryKey() string
	Execute(context.Context, any) (any, error)
}

Basic represents a basic job. Borrowing the terminology from inheritance, we can think of Basic jobs as the Abstract Base Class for all jobs. Basic jobs define execution, but do not define any behaviour around how/when the job is to be executed, and thus cannot be executed on their own.

type BlockHeaderSub

type BlockHeaderSub interface {
	Basic
	Subscribe(ctx context.Context) (ethereum.Subscription, chan *coretypes.Header, error)
	Unsubscribe(ctx context.Context)
}

BlockHeaderSub represents a block watcher job.

type Conditional

type Conditional interface {
	Polling
	Condition(ctx context.Context) bool
}

Conditional represents a conditional job.

type Custom

type Custom interface {
	Basic
	HasProducer
}

Custom Jobs are jobs that defines their own producer function. This is useful for adding custom job types without having to make a change to the core `offchain-sdk`.

type EthSubscribable

type EthSubscribable interface {
	Basic
	Subscribe(ctx context.Context) (ethereum.Subscription, chan coretypes.Log, error)
	Unsubscribe(ctx context.Context)
}

EthSubscribable represents a subscription to an ethereum event.

type HasMetrics

type HasMetrics interface {
	Basic
}

HasMetrics represents a struct that defines metrics for its internal functions.

type HasProducer

type HasProducer interface {
	Basic
	Producer(ctx context.Context, pool WorkerPool) error
}

HasProducer represents a struct that defines a producer.

func WrapConditional

func WrapConditional(c Conditional) HasProducer

Wrap Conditional, wraps a conditional job to conform to the producer interface.

func WrapJob

func WrapJob(j Basic) HasProducer

WrapJob wraps a basic job into a job that can be submitted to the worker pool.

func WrapPolling

func WrapPolling(c Polling) HasProducer

WrapPolling wraps a polling job into a conditional job, this is possible since, polling jobs are simply conditional jobs where `Condition()` always returns true. Cute little double wrap that allows us to re-use the producer from `conditional`.

type HasSetup

type HasSetup interface {
	Basic
	Setup(context.Context) error
}

HasSetup represents a job that has a setup function.

type HasTeardown

type HasTeardown interface {
	Basic
	Teardown() error
}

HasTeardown represents a job that has a teardown function.

type Polling

type Polling interface {
	Basic
	IntervalTime(ctx context.Context) time.Duration
}

Polling represents a polling job. Polling jobs are jobs that are run periodically at a given interval.

type Registry

type Registry struct {
	// mapRegistry is the underlying map registry of job types to
	types.Registry[string, Basic]
}

Registry is a registry of jobtypes to jobs.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns a new registry.

func (*Registry) Count

func (r *Registry) Count() uint64

Count returns the number of jobs in the registry.

func (*Registry) RegisterJob

func (r *Registry) RegisterJob(job Basic)

RegisterJob registers a job type to the registry.

type Subscribable

type Subscribable interface {
	Basic
	Subscribe(ctx context.Context) chan any
}

Subscribable represents a subscribable job.

type WorkerPool

type WorkerPool interface {
	Submit(func())
	SubmitAndWait(func())
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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