jobs

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GormStore

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

func NewGormStore

func NewGormStore(db *gorm.DB) *GormStore

func (*GormStore) InsertJob

func (s *GormStore) InsertJob(j *Job) error

func (*GormStore) Job

func (s *GormStore) Job(id uuid.UUID) (j Job, err error)

func (*GormStore) Jobs

func (s *GormStore) Jobs(o datastore.ListOptions) (jj []Job, err error)

func (*GormStore) UpdateJob

func (s *GormStore) UpdateJob(j *Job) error

type JSONResponse added in v0.6.0

type JSONResponse struct {
	ID            uuid.UUID `json:"jobId"`
	Status        Status    `json:"status"`
	Error         string    `json:"error"`
	Result        string    `json:"result"`
	TransactionID string    `json:"transactionId"`
	CreatedAt     time.Time `json:"createdAt"`
	UpdatedAt     time.Time `json:"updatedAt"`
}

Job HTTP response

type Job

type Job struct {
	ID            uuid.UUID      `gorm:"column:id;primary_key;type:uuid;"`
	Status        Status         `gorm:"column:status"`
	Error         string         `gorm:"column:error"`
	Result        string         `gorm:"column:result"`
	TransactionID string         `gorm:"column:transaction_id"`
	CreatedAt     time.Time      `gorm:"column:created_at"`
	UpdatedAt     time.Time      `gorm:"column:updated_at"`
	DeletedAt     gorm.DeletedAt `gorm:"column:deleted_at;index"`
	Do            Process        `gorm:"-"`
}

Job database model

func (*Job) BeforeCreate

func (j *Job) BeforeCreate(tx *gorm.DB) (err error)

func (Job) ToJSONResponse added in v0.6.0

func (j Job) ToJSONResponse() JSONResponse

func (*Job) Wait

func (j *Job) Wait(wait bool) error

type Process added in v0.6.0

type Process func(result *Result) error

type Result added in v0.6.0

type Result struct {
	Result        string
	TransactionID string
}

type Service

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

Service defines the API for job HTTP handlers.

func NewService

func NewService(store Store) *Service

NewService initiates a new job service.

func (*Service) Details

func (s *Service) Details(jobId string) (*Job, error)

Details returns a specific job.

func (*Service) List

func (s *Service) List(limit, offset int) (*[]Job, error)

List returns all jobs in the datastore.

type Status

type Status int
const (
	Unknown Status = iota
	Init
	Accepted
	NoAvailableWorkers
	QueueFull
	Error
	Complete
)

func StatusFromText

func StatusFromText(text string) Status

func (Status) MarshalText

func (s Status) MarshalText() ([]byte, error)

func (Status) String

func (i Status) String() string

func (*Status) UnmarshalText

func (s *Status) UnmarshalText(text []byte) error

type Store

type Store interface {
	Jobs(datastore.ListOptions) ([]Job, error)
	Job(id uuid.UUID) (Job, error)
	InsertJob(*Job) error
	UpdateJob(*Job) error
}

Store manages data regarding jobs.

type WorkerPool

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

func NewWorkerPool

func NewWorkerPool(logger *log.Logger, db Store, capacity uint, workerCount uint) *WorkerPool

func (*WorkerPool) AddJob

func (wp *WorkerPool) AddJob(do Process) (*Job, error)

AddJob will try to add a job to the workerpool

func (*WorkerPool) Stop

func (wp *WorkerPool) Stop()

Jump to

Keyboard shortcuts

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