jobs

package
v0.0.0-...-a25ac86 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToQueue

func AddToQueue(job Job)

AddToQueue adds a job to the Queue * Call this with a pre-defined job to add it to the queue

func AsyncRun

func AsyncRun(job Job)

AsyncRun attempts to execute a job asynchronously up to 3 times before giving up. It logs the time it took to execute the job and the number of attempts. It uses an exponential backoff strategy. This is a helper function that can be used to run any job asynchronously & is used to run both regular and irregular jobs.

func AsyncRunLimited

func AsyncRunLimited(job Job)

AsyncRunLimited is a helper function that limits the number of concurrent jobs to the number of tokens in the semaphore. It's used to run irregular jobs. It's used to run irregular jobs.

func StartQueue

func StartQueue()

StartQueue is the central controller for all irregularly scheduled jobs This function is meant to be called once at the start of the application and it will run in the background. It listens for jobs to be added to the queue and runs them asynchronously when they are added. It also listens for a shutdown signal and stops processing jobs when it receives it.

func StartSchedule

func StartSchedule()

StartSchedule is the central controller for all regularly scheduled jobs in the application This one is manually configured to run jobs at specific times. It uses the cron package to do this. This function is meant to be called once at the start of the application and it will run in the background.

func StopQueue

func StopQueue()

StopQueue signals the runner to stop processing irregular jobs

Types

type EmailJob

type EmailJob struct {
	From    string
	To      string
	Subject string
	Body    string
	Client  *mailjet.Client
}

func (EmailJob) Execute

func (e EmailJob) Execute() error

type HelloJob

type HelloJob struct {
	Greeting string
	Name     string
}

func (HelloJob) Execute

func (e HelloJob) Execute() error

type Job

type Job interface {
	Execute() error
}

Job is an interface that all jobs must implement It's meant to enforce a common method signature for all jobs and is usable for both regular and irregular jobs.

Jump to

Keyboard shortcuts

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