SQS: DeletePersist возвращает ошибку (500 при сбое Redis), fail-fast загрузка очередей, дефолты атрибутов при CreateQueue, защита SqsErrors от nil-deref
This commit is contained in:
@@ -361,30 +361,32 @@ func SaveMessagesSync(queueKey string, msgs []models.SqsMessage) error {
|
||||
// Синхронность обязательна: если удаление потеряется при рестарте пода,
|
||||
// сообщение «воскреснет» из Redis (факт: удалённые очереди возвращались
|
||||
// после рестарта, когда удаления были асинхронными).
|
||||
func DeleteMessagePersist(queueKey string, msgUuid string) {
|
||||
func DeleteMessagePersist(queueKey string, msgUuid string) error {
|
||||
if Client.Load() == nil || msgUuid == "" {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
hashKey := redisMsgHashPrefix + queueKey
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
if err := Client.Load().HDel(ctx, hashKey, msgUuid).Err(); err != nil {
|
||||
log.Errorf("persistence: HDel message %s/%s: %v", queueKey, msgUuid, err)
|
||||
return fmt.Errorf("HDel message %s/%s: %w", queueKey, msgUuid, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteMessagesPersist — удаляет несколько сообщений из Redis СИНХРОННО
|
||||
// (иначе удалённые сообщения воскреснут после рестарта пода).
|
||||
func DeleteMessagesPersist(queueKey string, uuids []string) {
|
||||
func DeleteMessagesPersist(queueKey string, uuids []string) error {
|
||||
if Client.Load() == nil || len(uuids) == 0 {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
hashKey := redisMsgHashPrefix + queueKey
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if err := Client.Load().HDel(ctx, hashKey, uuids...).Err(); err != nil {
|
||||
log.Errorf("persistence: HDel messages %s (%d): %v", queueKey, len(uuids), err)
|
||||
return fmt.Errorf("HDel messages %s (%d): %w", queueKey, len(uuids), err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PurgeMessagesPersist — удаляет ВСЕ сообщения очереди из Redis СИНХРОННО.
|
||||
@@ -519,8 +521,9 @@ func LoadAllQueues() (map[string]*models.Queue, error) {
|
||||
hashKey := redisMsgHashPrefix + k
|
||||
msgRaw, err := Client.Load().HGetAll(ctx, hashKey).Result()
|
||||
if err != nil {
|
||||
log.Errorf("persistence: HGetAll messages %q: %v", k, err)
|
||||
continue
|
||||
// Fail-fast: скрытая пустая очередь при недоступных сообщениях
|
||||
// хуже явной ошибки — сообщения остались бы невидимыми в Redis.
|
||||
return nil, fmt.Errorf("redis HGetAll messages %q: %w", k, err)
|
||||
}
|
||||
if len(msgRaw) > 0 {
|
||||
msgs := make([]models.SqsMessage, 0, len(msgRaw))
|
||||
|
||||
Reference in New Issue
Block a user