// Unlock releases an exclusive mongoDB lock for the provided id (if it exists)
Unlock releases an exclusive mongoDB lock for the provided id (if it exists)
// Unlock releases an exclusive mongoDB lock for the provided id ( if it exists )
func (l *Lock) Unlock(ctx context.Context, lockID string) {
	retries := 0
	for {
		_, err := l.Client.Unlock(ctx, lockID)
		if err == nil {
			if retries > 0 {
				log.Info(ctx, "unlocking succeeded after some retries", log.Data{"retries": retries})
			}
			return 
		}
		if retries >= UnlockMaxRetries {
			log.Error(ctx, "error unlocking", ErrUnlockMaxRetries)
			return 
		}
		retries++
		select {
		case <-time.After(UnlockPeriod):
			continue 
		case <-l.CloserChannel:
			log.Info(ctx, "stop unlocking lock. Mongo db is being closed", log.INFO)
			return 
		}
	}
}
func ( l * Lock ) Unlock ( ctx context . Context , lockID string ) { retries := 0 for { _ , err := l . Client . Unlock ( ctx , lockID ) if err == nil { if retries > 0 { log . Info ( ctx , " " , log . Data { " " : retries } ) } return } if retries >= UnlockMaxRetries { log . Error ( ctx , " " , ErrUnlockMaxRetries ) return } retries ++ select { case <- time . After ( UnlockPeriod ) : continue case <- l . CloserChannel : log . Info ( ctx , " " , log . INFO ) return } } }
Unlock releases an exclusive mongoDB lock for the provided id (if it exists)
Unlock releases an exclusive mongoDB lock for the provided id ( if it exists )
// This log is temporary, we might want to delete it in the future // Successful unlock // Failed too many times // Retry // Abort because the app is closing