queue

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: Unlicense Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownBank = errors.New("bank doesn't exist")

Functions

This section is empty.

Types

type Account

type Account struct {
	Account          *bank.Account
	TransactionsUpTo time.Time
	Transactions     []*bank.Transaction
}

type Job

type Job interface {
	// Position of the job in queue. If it is equal to zero then the job is
	// being or has been processed.
	Position() int
	Started() <-chan struct{}
	Credentials(login, pwd []byte, a <-chan string) (q <-chan string)
	Done() <-chan struct{}
	Results() ([]*Account, error)
}

type Queue

type Queue interface {
	Set(ctx context.Context, bank string) (Job, bool)
}

func NewSimpleQueue

func NewSimpleQueue(jobTimeout time.Duration,
	transactionsDoneUpTo time.Duration, cap int32) Queue

type SimpleQueue

type SimpleQueue struct {
	TransactionsUpTo time.Duration
	JobTimeout       time.Duration

	Queue []*SimpleQueueJob
	// contains filtered or unexported fields
}

func (*SimpleQueue) Position

func (s *SimpleQueue) Position(j *SimpleQueueJob) int32

Position returns the position of the job in queue. If it is equal to zero, the job is being or has been processed.

func (*SimpleQueue) Process

func (s *SimpleQueue) Process()

Process get the first element in queue and run it. This method blocks forever and there is no way to unblock it.

func (*SimpleQueue) Set

func (s *SimpleQueue) Set(ctx context.Context, bank string) (Job, bool)

Set a job in queue. It returns false if the queue is full. This method is thread safe.

type SimpleQueueJob

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

func (*SimpleQueueJob) Credentials

func (s *SimpleQueueJob) Credentials(login, pwd []byte, a <-chan string) (q <-chan string)

Credentials passes the username and password It should be called when the Started method closes. This method is meant to be called a single time so the credentials channel will be closed right after sending the credentials.

func (*SimpleQueueJob) Done

func (s *SimpleQueueJob) Done() <-chan struct{}

func (*SimpleQueueJob) Position

func (s *SimpleQueueJob) Position() int

func (*SimpleQueueJob) Results

func (s *SimpleQueueJob) Results() ([]*Account, error)

Results blocks until the job is done.

func (*SimpleQueueJob) Started

func (s *SimpleQueueJob) Started() <-chan struct{}

Jump to

Keyboard shortcuts

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