Skip to content

Commit 3fdcd8e

Browse files
committed
Update doc
1 parent 99cdbaa commit 3fdcd8e

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

modules/queue/queue.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,47 @@
22
// SPDX-License-Identifier: MIT
33

44
// Package queue implements a specialized concurrent queue system for Gitea.
5-
5+
//
66
// Terminology:
7-
7+
//
88
// 1. Item:
9-
// - An item can be a simple value, such as an integer, or a more complex structure that has multiple fields and
10-
// methods. Usually a item serves as a unit of work, sets of items will be sent to a handler to be processed.
11-
// - It's represented as a binary slice on the queue
12-
// - When an item serve as a unit of work generally it will be referred as a task
9+
// - An item can be a simple value, such as an integer, or a more complex structure that has multiple fields and
10+
// methods. Usually a item serves as a unit of work, sets of items will be sent to a handler to be processed.
11+
// - It's represented as a binary slice on the queue
12+
// - When an item serve as a unit of work generally it will be referred as a task
1313
//
1414
// 2. Batch:
15-
// - A collection of items that are grouped together for processing. Each worker receives a batch of items.
15+
// - A collection of items that are grouped together for processing. Each worker receives a batch of items.
1616
//
1717
// 3. Worker:
18-
// - Individual unit of execution designed to process items from the queue. It's a goroutine that calls the Handler.
19-
// - Workers will get new items through a channel (WorkerPoolQueue is responsible for the distribution).
20-
// - Workers operate in parallel. The default value of max workers is determined by the setting system.
18+
// - Individual unit of execution designed to process items from the queue. It's a goroutine that calls the Handler.
19+
// - Workers will get new items through a channel (WorkerPoolQueue is responsible for the distribution).
20+
// - Workers operate in parallel. The default value of max workers is determined by the setting system.
2121
//
2222
// 4. Handler (represented by HandlerFuncT type):
23-
// - It's the function responsible for processing items. Each active worker will call it.
24-
// - When processing batches, there might be instances where certain items remain unprocessed or "unhandled".
25-
// In such scenarios, the Handler ensures these unhandled items are returned to the base queue after a brief delay.
26-
// This mechanism is particularly beneficial in cases where the processing entity (like a document indexer) is
27-
// temporarily unavailable. It ensures that no item is skipped or lost due to transient failures in the processing
28-
// mechanism.
23+
// - It's the function responsible for processing items. Each active worker will call it.
24+
// - When processing batches, there might be instances where certain items remain unprocessed or "unhandled".
25+
// In such scenarios, the Handler ensures these unhandled items are returned to the base queue after a brief delay.
26+
// This mechanism is particularly beneficial in cases where the processing entity (like a document indexer) is
27+
// temporarily unavailable. It ensures that no item is skipped or lost due to transient failures in the processing
28+
// mechanism.
2929
//
3030
// 5. Base queue:
31-
// - Represents the underlying storage mechanism for the queue. There are several implementations:
32-
// - Channel: Uses Go's native channel constructs to manage the queue, suitable for in-memory queuing.
33-
// - LevelDB: Especially useful in persistent queues for single instances.
34-
// - Redis: Suitable for clusters, where we may have multiple nodes.
35-
// - Dummy: This is special, it's not a real queue, it's a immediate no-op queue, which is useful for tests.
36-
// - They all have the same abstraction, the same interface, and they are tested by the same testing code.
31+
// - Represents the underlying storage mechanism for the queue. There are several implementations:
32+
// - Channel: Uses Go's native channel constructs to manage the queue, suitable for in-memory queuing.
33+
// - LevelDB: Especially useful in persistent queues for single instances.
34+
// - Redis: Suitable for clusters, where we may have multiple nodes.
35+
// - Dummy: This is special, it's not a real queue, it's a immediate no-op queue, which is useful for tests.
36+
// - They all have the same abstraction, the same interface, and they are tested by the same testing code.
3737
//
3838
// 6. WorkerPoolQueue:
3939
// - It's responsible to glue all together, using the "base queue" to provide "worker pool" functionality. It creates
40-
// new workers if needed and can flush the queue, running all the items synchronously till it finishes.
40+
// new workers if needed and can flush the queue, running all the items synchronously till it finishes.
4141
// - Its "Push" function doesn't block forever, it will return an error if the queue is full after the timeout.
4242
//
4343
// 7. Manager:
4444
// - The purpose of it is to serve as a centralized manager for multiple WorkerPoolQueue instances. Whenever we want
45-
// to create a new queue, flush, or get a specific queue, we have to use it.
45+
// to create a new queue, flush, or get a specific queue, we have to use it.
4646
//
4747
// A queue can be "simple" or "unique". A unique queue will try to avoid duplicate items.
4848
// Unique queue's "Has" function can be used to check whether an item is already in the queue,
@@ -53,11 +53,11 @@
5353
// If you want another kind of items to run, you would have to call the manager to create a new WorkerPoolQueue for you
5454
// with a different handler that works with this new type of item. As an example of this:
5555
//
56-
// func Init() error {
57-
// itemQueue = queue.CreateSimpleQueue(graceful.GetManager().ShutdownContext(), "item", handler)
58-
// ...
59-
// }
60-
// func handler(items ...*admin_model.Item) []*admin_model.Item { ... }
56+
// func Init() error {
57+
// itemQueue = queue.CreateSimpleQueue(graceful.GetManager().ShutdownContext(), "item", handler)
58+
// ...
59+
// }
60+
// func handler(items ...*admin_model.Item) []*admin_model.Item { ... }
6161
//
6262
// As you can see, the handler defined the admin_model.Item type for the queue
6363
package queue

0 commit comments

Comments
 (0)