Created
September 22, 2022 17:57
-
-
Save Samrose-Ahmed/f1ec2b5dc37d0aafadd07a488fa8d25d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun checkDuplicate(sequencer: String): Boolean { | |
// TTL to expire old DynamoDB items | |
val expireTime = ((System.currentTimeMillis() / 1000L) + DDB_ITEM_EXPIRE_SECONDS).toString() | |
val attrs = mapOf( | |
"sequencer" to AttributeValue(sequencer), | |
"ttl" to AttributeValue().apply { this.setN(expireTime) } | |
) | |
val req = PutItemRequest(DUPLICATES_DDB_TABLE_NAME, attrs) | |
.apply { this.conditionExpression = "attribute_not_exists(sequencer)" } | |
try { ddb.putItem(req) } | |
catch (e: ConditionalCheckFailedException) { | |
return true | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment