jobs

package
v0.0.0-...-cefa481 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExchangeRateResource

type ExchangeRateResource struct {
	Status string             `json:"result"`
	Rates  map[string]float64 `json:"conversion_rates"`
}

type ExchangeRateUpdate

type ExchangeRateUpdate struct {
	Add bool
	// contains filtered or unexported fields
}

func (ExchangeRateUpdate) Run

func (job ExchangeRateUpdate) Run()

type JobAdapter

type JobAdapter struct {
	// contains filtered or unexported fields
}

func (*JobAdapter) NewExchangeRateUpdate

func (adapter *JobAdapter) NewExchangeRateUpdate() ExchangeRateUpdate

type JobInitializer

type JobInitializer struct {
	// contains filtered or unexported fields
}

func NewJobInitializer

func NewJobInitializer(port services.AppServicesPort) *JobInitializer

func (*JobInitializer) Init

func (inz *JobInitializer) Init()

For each job, create a new struct with the name of the job as the struct name that has a bool field "Add" to indicate if the job should be added to the job queue, a "appPort" field of type "services.AppServicesPort" which will be used to access the application services, and a "scheduler" field of type "*gocron.Scheduler" which will be used to schedule the job.

Return a new instance of the job using a factory method that have the "JobAdapter" as a receiver. Then implement a "Run" method on the job struct, which is where the job logic is implemented. The job will be automatically added to the job queue, if the "Add" field is set to true.

The "Add" id used as a way to determine if the job should be added to the job queue and if the implementation is still being worked on, which in this case can be set to false. And when implementation of the job is completed to be added, the "Add" field should be set to true.

Example:

type YourJobName struct {
	Add			bool
	appPort		services.AppServicesPort
	scheduler	*gocron.Scheduler
}

func (adapter *JobAdapter) NewYourJobName() YourJobName {
	return YourJobName{
		Add: true, // Set to false if the implementation is still being worked on, or to dequeue
		appPort: adapter.appPort,
		scheduler: adapter.scheduler,
	}
}

func (job YourJobName) Run() {
	// Your job logic here
}

Init will auto run all jobs that have the "Add" field set to true

Jump to

Keyboard shortcuts

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