Files
SQS-service/app/models/helpers.go
T
Repinoid 3a52960d5b P1.4: tenant-индекс очередей (O(1) подсчёт/список вместо скана)
Введён тип QueueStore с индексом accessKey→{queueName}. Мутации очередей идут через
AddQueue/RemoveQueue (create/delete/restore/config/seed/admin), подсчёт и список —
через CountTenantQueues/TenantQueueNames. Устранены O(total) скан-по-префиксу в
countTenantQueues, deleteTenant, listTenantQueues, createTenantQueue. API SyncQueues
(Queues, Lock) сохранён — остальной код не затронут.
2026-10-06 18:36:03 +03:00

50 lines
1.0 KiB
Go

package models
import (
"errors"
"fmt"
"math/rand"
"time"
)
// ---- Unit Tests ----
func ResetApp() {
CurrentEnvironment = Environment{}
ResetResources()
}
func ResetResources() {
SyncQueues.Lock()
SyncQueues.Queues = make(map[string]*Queue)
SyncQueues.ResetQueueIndex()
SyncQueues.Unlock()
}
func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func generateRandomLatency() (time.Duration, error) {
min := CurrentEnvironment.RandomLatency.Min
max := CurrentEnvironment.RandomLatency.Max
if min == 0 && max == 0 {
return time.Duration(0), nil
}
var randomLatencyValue int
if max == min {
randomLatencyValue = max
} else {
randomLatencyValue = rand.Intn(max-min) + min
}
randomDuration, err := time.ParseDuration(fmt.Sprintf("%dms", randomLatencyValue))
if err != nil {
return time.Duration(0), errors.New(fmt.Sprintf("Error parsing random latency value: %dms", randomLatencyValue))
}
return randomDuration, nil
}