apifactory

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: MIT Imports: 16 Imported by: 0

README

apifactory

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFailedQueue

func NewFailedQueue(log *logger.Logger, af *apiFactory, heartbeat, poll time.Duration) sidejob.WorkerGroup

NewFailedQueue returns a apifactory failed queue

func NewProcessQueue

func NewProcessQueue(log *logger.Logger, af *apiFactory, heartbeat, poll, exponentialBase time.Duration, maxErrorCount int) sidejob.WorkerGroup

NewProcessQueue returns a new process queue

Types

type APIFactory

type APIFactory interface {
	Start(count int64) (chan interface{}, chan interface{})
	Stop(ctx context.Context)
	UpdateProcess(count int64)
	UpdateFailed(count int64)
	AddRateLimit(host, bucket string, count int64) error
	Publish(cx *Context) error
}

APIFactory ...

func NewAPIFactory

func NewAPIFactory(conf *Config, log *logger.Logger, sj sidejob.Sidejob, gcstore googlestorage.GCStorage) (APIFactory, error)

NewAPIFactory returns a new APIfactory object

type Config

type Config struct {
	Heartbeat       time.Duration
	Poll            time.Duration
	ExponentialBase time.Duration
	MaxErrorCount   int
}

type Context

type Context struct {
	Request        *getter.Request
	Response       *getter.Response
	Next           time.Time
	Published      time.Time
	Processed      time.Time
	ProcessingTime time.Duration
	ParsedQueue    string
	QueueErrors    []string
	PersistHash    string
}

Context contains details about a request in apifactory

func NewContext

func NewContext(payload string) (*Context, error)

NewContext creates a context from a string

func (*Context) CheckPersistedData

func (c *Context) CheckPersistedData(gcs googlestorage.GCStorage) (bool, error)

CheckPersistedData ...

func (*Context) IsAtMaxErrorCount

func (c *Context) IsAtMaxErrorCount(max int) bool

IsAtMaxErrorCount checks if the number of failures is equal to max

func (*Context) IsPastWaitingTime

func (c *Context) IsPastWaitingTime() bool

IsPastWaitingTime checks if the job is beyond the waiting time

func (*Context) IsRateLimited

func (c *Context) IsRateLimited() bool

IsRateLimited checks if request was rate limited

func (*Context) IsSuccess

func (c *Context) IsSuccess() bool

IsSuccess checks if the response was successful or not

func (*Context) LogRequestFailure

func (c *Context) LogRequestFailure(log *logger.Logger, name string)

LogRequestFailure logs a request failure

func (*Context) LogRequestSuccess

func (c *Context) LogRequestSuccess(log *logger.Logger, name string, fromStorage bool)

LogRequestSuccess logs a successful request

func (*Context) MarkAsProcessed

func (c *Context) MarkAsProcessed()

MarkAsProcessed update processed timestamp and processing time

func (*Context) PersistData

func (c *Context) PersistData(gcs googlestorage.GCStorage) error

PersistData ...

func (*Context) Prepare

func (c *Context) Prepare()

func (*Context) QueueResponseError

func (c *Context) QueueResponseError()

QueueResponseError adds the response error to the queue of error

func (*Context) String

func (c *Context) String(log *logger.Logger) string

func (*Context) UpdateNextProcessingTime

func (c *Context) UpdateNextProcessingTime(delta time.Duration)

UpdateNextProcessingTime updates the processing time to the next value

Jump to

Keyboard shortcuts

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