MCPcopy Index your code
hub / github.com/flant/shell-operator / GetSnapshot

Method GetSnapshot

pkg/task/queue/queue_set.go:151–172  ·  view source on GitHub ↗

GetSnapshot returns a snapshot of all queues at the time of the call. This is useful for iteration when you need to call methods on the queues that might acquire locks, preventing deadlocks. The returned slice is a snapshot and will not reflect subsequent changes. The main queue (tqs.MainName) is a

()

Source from the content-addressed store, hash-verified

149// The returned slice is a snapshot and will not reflect subsequent changes.
150// The main queue (tqs.MainName) is always placed first in the list.
151func (tqs *TaskQueueSet) GetSnapshot() []*TaskQueue {
152 tqs.logger.Debug("GetSnapshot: creating snapshot of queues")
153
154 allQueues := tqs.Queues.List()
155 queues := make([]*TaskQueue, 0, len(allQueues))
156
157 // First, add the main queue if it exists
158 if mainQueue := tqs.GetMain(); mainQueue != nil {
159 queues = append(queues, mainQueue)
160 }
161
162 // Then add all other queues
163 for _, queue := range allQueues {
164 if queue.Name != tqs.MainName {
165 queues = append(queues, queue)
166 }
167 }
168
169 tqs.logger.Debug("GetSnapshot: creating snapshot of queues done")
170
171 return queues
172}
173
174// IterateSnapshot creates a snapshot of all queues and iterates over the copy.
175// This is safer than Iterate() when you need to call queue methods inside the callback,

Callers 1

IterateSnapshotMethod · 0.95

Calls 2

GetMainMethod · 0.95
ListMethod · 0.45

Tested by

no test coverage detected