diff --git a/bot/logic/close.go b/bot/logic/close.go index c6efd7a..f65a0a4 100644 --- a/bot/logic/close.go +++ b/bot/logic/close.go @@ -40,6 +40,19 @@ func CloseTicket(ctx context.Context, cmd registry.CommandContext, reason *strin return } + lock, err := redis.TakeTicketCloseLock(ctx, uint64(ticket.Id)) + if err != nil { + cmd.HandleError(err) + return + } + + defer func() { + _, unlockErr := lock.UnlockContext(ctx) + if unlockErr != nil { + sentry.ErrorWithContext(unlockErr, cmd.ToErrorContext()) + } + }() + defer func() { if !success { if err := dbclient.Client.AutoCloseExclude.Exclude(ctx, ticket.GuildId, ticket.Id); err != nil { diff --git a/bot/redis/openlock.go b/bot/redis/openlock.go index 7b83b74..db41909 100644 --- a/bot/redis/openlock.go +++ b/bot/redis/openlock.go @@ -24,3 +24,11 @@ func TakeTicketOpenLock(ctx context.Context, guildId uint64) (Mutex, error) { return mu, nil } + +func TakeTicketCloseLock(ctx context.Context, ticketId uint64) (Mutex, error) { + mu := rs.NewMutex(fmt.Sprintf("tickets:closelock:%d", ticketId), redsync.WithExpiry(TicketOpenLockExpiry)) + if err := mu.LockContext(ctx); err != nil { + return nil, err + } + return mu, nil +}