requests

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package requests provides structures and functions to handle requests.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPriority means that requested priority is out of bounds.
	// Either general bounds (HiPrio, LoPrio) or allowed priority bounds for
	// request owner.
	ErrPriority = errors.New("requested priority out of bounds")
	// ErrInvalidTimeRange means that requested ValidAfter date is after Deadline value.
	ErrInvalidTimeRange = errors.New("requested time range illegal - ValidAfter must be before Deadline")
	// ErrDeadlineInThePast means that requested Deadline date is in the past.
	ErrDeadlineInThePast = errors.New("Deadline in the past")
	// ErrWorkerNotAssigned means that user tries to call method which regards
	// worker although worker wasn't assigned yet.
	ErrWorkerNotAssigned = errors.New("worker not assigned")
	// ErrModificationForbidden means that user tries to modify request which
	// is in state that forbids any changes.
	ErrModificationForbidden = errors.New("action cannot be executed in current state")
)

Functions

This section is empty.

Types

type ReqsCollection

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

ReqsCollection contains information (also historical) about handled requests. It implements Requests, RequestsManager and WorkerChange interfaces.

func NewRequestQueue

NewRequestQueue provides initialized priority queue for requests.

func (*ReqsCollection) AcquireWorker

func (reqs *ReqsCollection) AcquireWorker(reqID boruta.ReqID) (boruta.AccessInfo, error)

AcquireWorker is part of implementation of Requests interface. When worker is assigned to the requests then owner of such requests may call AcquireWorker to get all information required to use assigned worker.

func (*ReqsCollection) Close

func (reqs *ReqsCollection) Close(reqID boruta.ReqID) error

Close verifies if request time has been exceeded and if so closes it. If request is still valid to continue it's job an error is returned. It is part of implementation of RequestsManager interface.

func (*ReqsCollection) CloseRequest

func (reqs *ReqsCollection) CloseRequest(reqID boruta.ReqID) error

CloseRequest is part of implementation of Requests interface. It checks that request is in WAIT state and changes it to CANCEL or in INPROGRESS state and changes it to DONE. NotFoundError may be returned if request with given reqID doesn't exist in the queue or ErrModificationForbidden if request is in state which can't be closed.

func (*ReqsCollection) Finish

func (reqs *ReqsCollection) Finish()

Finish releases requestTimes queues and stops started goroutines.

func (*ReqsCollection) Get

func (reqs *ReqsCollection) Get(rid boruta.ReqID) (boruta.ReqInfo, error)

Get retrieves request's information structure for request with given ID. It is part of implementation of RequestsManager interface.

func (*ReqsCollection) GetRequestInfo

func (reqs *ReqsCollection) GetRequestInfo(reqID boruta.ReqID) (boruta.ReqInfo, error)

GetRequestInfo is part of implementation of Requests interface. It returns ReqInfo for given request ID or NotFoundError if request with given ID doesn't exits in the collection.

func (*ReqsCollection) InitIteration

func (reqs *ReqsCollection) InitIteration() error

InitIteration initializes queue iterator and sets global lock for requests structures. It is part of implementation of RequestsManager interface.

func (*ReqsCollection) ListRequests

func (reqs *ReqsCollection) ListRequests(filter boruta.ListFilter, si *boruta.SortInfo,
	paginator *boruta.RequestsPaginator) ([]boruta.ReqInfo, *boruta.ListInfo, error)

ListRequests is part of implementation of Requests interface. It returns slice of ReqInfo that matches ListFilter. Returned slice is sorted by SortInfo. It is possible to sort by following items: ID (default), Priority, State, ValidAfter and Deadline dates in ascending (default) or descending order. If paginator was set then the sorted list will be divided into pages with paginator.Limit requests at most per page. If paginator.Direction is forward then listed requests begin after the paginator.ID. In case of backward direction listed requests end just before paginator.ID.

func (*ReqsCollection) NewRequest

func (reqs *ReqsCollection) NewRequest(caps boruta.Capabilities,
	priority boruta.Priority, owner boruta.UserInfo, validAfter time.Time,
	deadline time.Time) (boruta.ReqID, error)

NewRequest is part of implementation of Requests interface. It validates provided arguments and creates request or returns an error. Caller must make sure that provided time values are in UTC.

func (*ReqsCollection) Next

func (reqs *ReqsCollection) Next() (boruta.ReqID, bool)

Next gets next ID from request queue. Method returns {ID, true} if there is pending request or {ReqID(0), false} if queue's end has been reached. It is part of implementation of RequestsManager interface.

func (*ReqsCollection) OnWorkerFail

func (reqs *ReqsCollection) OnWorkerFail(worker boruta.WorkerUUID)

OnWorkerFail sets request being processed by failed worker into FAILED state.

func (*ReqsCollection) OnWorkerIdle

func (reqs *ReqsCollection) OnWorkerIdle(worker boruta.WorkerUUID)

OnWorkerIdle triggers ValidMatcher to rematch requests with idle worker.

func (*ReqsCollection) ProlongAccess

func (reqs *ReqsCollection) ProlongAccess(reqID boruta.ReqID) error

ProlongAccess is part of implementation of Requests interface. When owner of the request has acquired worker that to extend time for which the worker is assigned to the request.

func (*ReqsCollection) Run

func (reqs *ReqsCollection) Run(rid boruta.ReqID, worker boruta.WorkerUUID) error

Run starts job performing the request on the worker. It is part of implementation of RequestsManager interface.

func (*ReqsCollection) TerminateIteration

func (reqs *ReqsCollection) TerminateIteration()

TerminateIteration releases queue iterator if iterations are in progress and release global lock for requests structures. It is part of implementation of RequestsManager interface.

func (*ReqsCollection) Timeout

func (reqs *ReqsCollection) Timeout(rid boruta.ReqID) error

Timeout sets request to TIMEOUT state after Deadline time is exceeded. It is part of implementation of RequestsManager interface.

func (*ReqsCollection) UpdateRequest

func (reqs *ReqsCollection) UpdateRequest(src *boruta.ReqInfo) error

UpdateRequest is part of implementation of Requests interface. It may be used to modify ValidAfter, Deadline or Priority of request. Caller should pass pointer to new ReqInfo struct which has any of these fields set. Zero value means that field shouldn't be changed. All fields that cannot be changed are ignored.

func (*ReqsCollection) VerifyIfReady

func (reqs *ReqsCollection) VerifyIfReady(rid boruta.ReqID, now time.Time) bool

VerifyIfReady checks if the request is ready to be run on worker. It is part of implementation of RequestsManager interface.

Jump to

Keyboard shortcuts

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