Skip to content

Instantly share code, notes, and snippets.

@Samrose-Ahmed
Created September 22, 2022 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Samrose-Ahmed/f1ec2b5dc37d0aafadd07a488fa8d25d to your computer and use it in GitHub Desktop.
Save Samrose-Ahmed/f1ec2b5dc37d0aafadd07a488fa8d25d to your computer and use it in GitHub Desktop.
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