30 lines
852 B
Go
30 lines
852 B
Go
package queue
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
goredis "github.com/redis/go-redis/v9"
|
|
|
|
kmsvcredis "forgejo.riotpiao.com/rock/kmsvc-manage/internal/redis"
|
|
)
|
|
|
|
type ChangeVisibilityService struct {
|
|
Redis *goredis.Client
|
|
}
|
|
|
|
// ChangeMessageVisibility implements ChangeMessageVisibility (design.md
|
|
// §2b): extends (or shortens) how long a received message stays invisible
|
|
// to other consumers, without affecting its receive count.
|
|
func (s *ChangeVisibilityService) ChangeMessageVisibility(ctx context.Context, queueName, receiptHandle string, newTimeout time.Duration) error {
|
|
ok, err := kmsvcredis.ExtendVisibility(ctx, s.Redis, queueName, receiptHandle, newTimeout)
|
|
if err != nil {
|
|
return fmt.Errorf("change visibility %s: %w", queueName, err)
|
|
}
|
|
if !ok {
|
|
return fmt.Errorf("receipt handle not found or already expired")
|
|
}
|
|
return nil
|
|
}
|