Documentation ¶
Index ¶
- Constants
- Variables
- func ErrQueueEntryTimedOut(key Key) error
- func ErrQueueNoAvailableItems(key Key) error
- func ErrQueueValueDisappeared(key Key) error
- type Detail
- type Error
- type Items
- type Key
- type KeyError
- type Mapper
- type Progress
- type Queue
- func (q *Queue) ActiveItems() Items
- func (q *Queue) AddLimit(limit int)
- func (q *Queue) Cancel(anime domain.AnimeBase)
- func (q *Queue) Close() (err error)
- func (q *Queue) Collector() prometheus.Collector
- func (q *Queue) Contains(anime domain.AnimeBase) (found bool)
- func (q *Queue) Delete(anime domain.AnimeBase)
- func (q *Queue) ErrC() <-chan error
- func (q *Queue) Get(anime domain.AnimeBase) (value *State, ok bool)
- func (q *Queue) GetLimit() int
- func (q *Queue) InactiveItems() Items
- func (q *Queue) IsActive(anime domain.AnimeBase) (isActive bool)
- func (q *Queue) IsBusy() bool
- func (q *Queue) L(ctx context.Context) *zap.Logger
- func (q *Queue) Len() int64
- func (q *Queue) Notifier() <-chan struct{}
- func (q *Queue) Pause()
- func (q *Queue) Paused() bool
- func (q *Queue) Pop() (anime domain.AnimeBase, state *State, ok bool)
- func (q *Queue) PushBack(anime domain.AnimeBase, state *State) (pushed bool)
- func (q *Queue) PushFront(anime domain.AnimeBase, state *State) (pushed bool)
- func (q *Queue) Restart(anime domain.AnimeBase)
- func (q *Queue) Resume()
- func (q *Queue) Update(anime domain.AnimeBase, state *State)
- func (q *Queue) UpdateProgress(anime domain.AnimeBase, progress Progress)
- func (q *Queue) UpdateUnmanaged(cb func(Key, *State) bool)
- type StartedFrom
- type State
- func (v *State) Active() bool
- func (v *State) Cancel()
- func (v *State) Clone() (value *State)
- func (v *State) Close() (err error)
- func (v *State) Current() (*Detail, bool)
- func (v *State) Done(err error)
- func (v *State) Init()
- func (v *State) IsUnmanaged() bool
- func (v *State) OnUpdate()
- func (v *State) Restart()
- func (v *State) TimedOut(from time.Time) bool
- func (v *State) ToggleUnmanaged()
- func (v *State) UpdateProgress(progress Progress)
- func (v *State) UpdatedAt() time.Time
Constants ¶
const ( // ErrQueueTimeout is thrown when an item hasn't been updated by the timeout variable defined. ErrQueueTimeout = Error("queue entry timed-out") // ErrQueueNoAvailableItem is thrown when an item does not have any items left to push. ErrQueueNoAvailableItem = Error("no available items") // ErrQueueRestart is used when one wants to restart the current active item. ErrQueueRestart = Error("queue entry restart") // ErrQueueCanceled is used when a user sends an empty struct{}{} to `value.Cancel`. ErrQueueCanceled = Error("queue item canceled") // ErrValueDisappeared is used when the corresponding value for a key suddenly // turned into a <nil>. This could only happen, if someone decided to set the // pointer to <nil>, however on general terms it's used to prevent deadlocks within // the popAwait() routine. ErrValueDisappeared = Error("value disappeared") )
const ( // DefaultTick defines the Pop goroutine ticker's duration. DefaultTick = 30 * time.Second )
Variables ¶
var ( // AcquireTTL is how long we'll wait to Acquire() a sempahore release. AcquireTTL = 1 * time.Second // ManagedTTL is how long till a timeout occurs for un-updated entry that's managed. ManagedTTL = 30 * time.Second // UnmanagedTTL is how long till a timeout occurs for un-updated entry that's unmanaged. UnmanagedTTL = 10 * time.Minute )
Functions ¶
func ErrQueueEntryTimedOut ¶
ErrQueueEntryTimedOut throws ErrQueueTimeout for the specified Key.
func ErrQueueNoAvailableItems ¶
ErrQueueNoAvailableItems throws ErrQueueNoAvailableItem for the specified Key.
func ErrQueueValueDisappeared ¶
ErrQueueValueDisappeared throws ErrValueDisappeared for the specified Key.
Types ¶
type KeyError ¶
type KeyError struct { Key Key // contains filtered or unexported fields }
KeyError targets a 'queue.Key' with an error message.
type Progress ¶
type Progress struct { Type string // @refer to 'pkg/websocket/protocol' ProgressType Percentage float64 Speed float64 CurrentFilesize *float64 Filesize *float64 CurrentDuration *float64 Duration *float64 }
Progress defines the progress for a value whilst it's in queue.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
func NewCustomQueue ¶
func (*Queue) ActiveItems ¶
func (*Queue) Cancel ¶
Cancel attempts to cancel out the current active item. If the item is not canceled it'll call the inactive Delete().
func (*Queue) Close ¶
Close will clear out all the active and inactive items. On-going active items will get canceled here.
func (*Queue) Collector ¶
func (q *Queue) Collector() prometheus.Collector
Collector creates a `prometheus.Collector` with metrics such metrics such as `active`, `inactive` and `limit` guage statistics.
func (*Queue) Contains ¶
Contains will return true if the key is stored in the active or inactive queue.
func (*Queue) Delete ¶
Delete removes the queue entry (it does not send an empty to `.Cancel` though)
func (*Queue) Get ¶
Get will return the value in pointer form, if it returns nil, the item probably does not exist.
func (*Queue) InactiveItems ¶
func (*Queue) IsBusy ¶
IsBusy returns true if there's items in the queue and there's a semaphore allocation (someone's ready to take the work).
func (*Queue) Notifier ¶
func (q *Queue) Notifier() <-chan struct{}
Notifier will trigger when an item is added to the queue
func (*Queue) UpdateProgress ¶
type StartedFrom ¶
type StartedFrom int
const ( StartedFrom_AutoDownload StartedFrom = iota << 1 StartedFrom_Web )
func (StartedFrom) String ¶
func (s StartedFrom) String() string
StartedFrom implements fmt.Stringer
type State ¶
type State struct { Progress Progress Details []Detail StartedFrom StartedFrom // contains filtered or unexported fields }
State is the queue struct, where we hold the available items along with the progress. Details contain all the possible iterations
func (*State) Done ¶
Done will attempt to close off any progress to the value given the error passed.
func (*State) IsUnmanaged ¶
IsUnmanaged returns if the queue value is managed by us, or we're awaiting something.
func (*State) TimedOut ¶
TimedOut checks if the value is native, if it's not native it'll check if the `updatedAt` entry is less than the time provided minus 30 seconds.
func (*State) ToggleUnmanaged ¶
func (v *State) ToggleUnmanaged()