Documentation
¶
Index ¶
Constants ¶
const FetchFromDBWatermarkRatio = 2
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
An Item is something we manage in a priority queue.
type PriorityQueue ¶
type PriorityQueue []*Item
A PriorityQueue implements heap.Interface and holds Items.
func (PriorityQueue) Len ¶
func (pq PriorityQueue) Len() int
func (PriorityQueue) Less ¶
func (pq PriorityQueue) Less(i, j int) bool
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() interface{}
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(x interface{})
func (PriorityQueue) Swap ¶
func (pq PriorityQueue) Swap(i, j int)
type TaskQueue ¶
type TaskQueue struct { Tenant *entity.Tenant DelayTasks interface{} // TODO: time wheel CronTasks interface{} // TODO: time wheel UserTasks *PriorityQueue // contains filtered or unexported fields }
TaskQueue is in-memory cache for tenant tasks and resource quota, automatically handling fetching tasks from database when necessary.
func NewTaskQueue ¶
func (*TaskQueue) EnqueueUserTask ¶
EnqueueUserTask put task back to the priority queue, adding delta to task's priority. This is useful when task has to be retried as soon as possible before processing other tasks.
func (*TaskQueue) FetchTasks ¶
func (c *TaskQueue) FetchTasks()
FetchTasks read tasks from database and populate in-memory queue
func (*TaskQueue) PopAllUserTasks ¶
func (*TaskQueue) PopUserTasks ¶
PopUserTasks pops at most n entity.UserTasks from cache, returns tasks and the actual number successfully popped. When the number of cached entity.UserTasks is zero or less than FetchFromDBWatermarkRatio * n, it will populate tasks in background.