Skip to content

Commit

Permalink
Adding 🍀 AWS DynamoDb 🔒 lock support removing extra logs #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsaniara committed Aug 7, 2021
1 parent 5e5494d commit 66c56c6
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions goIntervalLock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
"github.com/aws/aws-sdk-go/service/dynamodb/expression"
"github.com/go-redis/redis/v8"
"log"
"time"
)

Expand Down Expand Up @@ -68,12 +67,11 @@ func (s *Locker) DynamoDbLock(ctx context.Context, key string, lockTtl time.Dura
// Make the DynamoDB Query API call
result, _ := s.dynamoClient.ScanWithContext(ctx, params)

log.Printf("--------------result.Items: %s", result.Items)
if len(result.Items) > 0 {
return false, nil
}

insert, errPut := s.dynamoClient.PutItemWithContext(ctx, &dynamodb.PutItemInput{
_, errPut := s.dynamoClient.PutItemWithContext(ctx, &dynamodb.PutItemInput{
Item: DynamoDbUnlockMarshal(key),
TableName: aws.String(Prefix),
})
Expand All @@ -82,19 +80,16 @@ func (s *Locker) DynamoDbLock(ctx context.Context, key string, lockTtl time.Dura
return false, errPut
}

log.Printf("--------------insert: %s", insert)

return true, nil

}

func (s *Locker) DynamoDbUnlock(ctx context.Context, key string) error {
if s.dynamoClient != nil {
item, _ := s.dynamoClient.DeleteItemWithContext(ctx, &dynamodb.DeleteItemInput{
_, _ = s.dynamoClient.DeleteItemWithContext(ctx, &dynamodb.DeleteItemInput{
Key: DynamoDbUnlockMarshal(key),
TableName: aws.String(Prefix),
})
log.Printf("DynamoDbUnlock:%s\n", item)
}
return nil
}
Expand Down

0 comments on commit 66c56c6

Please sign in to comment.