hjob

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: MIT Imports: 4 Imported by: 1

README

hexa-job handle jobs for hexa

Install

go get github.com/kamva/hexa-job

Proposal

  • Add pulsar driver

Todo:

  • write sample code to shutdown cron jobs server gracefully.
  • Write Tests.
  • Add badges to readme.
  • CI.

Documentation

Overview

Package hjob contains interfaces to define workers to process background jobs. --------------------------------

Index

Constants

View Source
const Version = "1.0.0"

Version is the package current version.

Variables

This section is empty.

Functions

This section is empty.

Types

type CronJob

type CronJob struct {
	Name  string // required
	Queue string
	// Retry specify retry counts of the job.
	// 0: means that throw job away (and dont push to dead queue) on first fail.
	// -1: means that push job to the dead queue on first fail.
	Retry int
}

CronJob is a new instance of cron job that should run in schedules time.

func NewCronJob

func NewCronJob(name string) *CronJob

NewCronJob returns new cron job instance

func NewCronJobWithQueue

func NewCronJobWithQueue(name string, queue string) *CronJob

NewCronJobWithQueue returns new cron job instance

type CronJobHandlerFunc

type CronJobHandlerFunc func(ctx context.Context) error

CronJobHandlerFunc is the handler of each cron job in the worker.

type CronJobs

type CronJobs interface {
	// Register handler for new cron job
	Register(spec string, cJob *CronJob, handler CronJobHandlerFunc) error
	hexa.Runnable
}

CronJobs get your cron-jobs specs

type Job

type Job struct {
	Name  string // required
	Queue string
	// Retry specify retry counts of the job.
	// 0: means that throw job away (and dont push to dead queue) on first fail.
	// -1: means that push job to the dead queue on first fail.
	Retry     int
	Timeout   time.Duration
	ProcessAt *time.Time  // Process the job at specific time.
	Payload   interface{} // It can be any struct.
}

Job is a new instance of job to push to the queue by Jobs interface

func NewJob

func NewJob(name string, payload interface{}) *Job

NewJob returns new job instance

func NewJobWithQueue

func NewJobWithQueue(name string, queue string, p interface{}) *Job

NewJobWithQueue returns new job instance

type JobHandlerFunc

type JobHandlerFunc func(context.Context, Payload) error

JobHandlerFunc is the handler of each job in the worker.

type Jobs

type Jobs interface {
	// Push push job to the default queue
	Push(context.Context, *Job) error
}

Jobs pushes jobs to process by worker.

type Payload

type Payload interface {
	Decode(payload interface{}) error
}

func NewJsonPayload

func NewJsonPayload(p []byte) Payload

type Worker

type Worker interface {
	// Register handler for new job
	Register(name string, handlerFunc JobHandlerFunc) error
	hexa.Runnable
}

Worker is the background jobs worker

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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