python - boto3 dynamodb batch_writer 如何执行回滚
问题描述
我正在使用 boto3 访问 AWS dynamodb 表并对其进行批量写入,这是示例代码:
with table.batch_writer() as batch:
try:
for i in range(10):
id = uuid.uuid4().hex
# A function which perform a job and finish with write to the table
# If the job fails, the function will raise an exception
write_to_table(batch, id)
except:
# Perform a rollback
print("{} failed".format(id))
是否可以使用BatchWriteItem回滚到整个批次?(例如在 except 块中)。
谢谢。
解决方案
我找到了一个解决方案,但我不确定它是否是一个好的解决方案:
batch = table.batch_writer()
try:
for i in range(10):
id = uuid.uuid4().hex
write_to_table(batch, id)
batch._flush()
except:
print("passive rollback")
推荐阅读
- sql - SQL Server 中的存储过程,带有选择查询然后 if 条件然后插入查询
- java - 如何获取单元格的列字母?
- reactjs - Gatsby:将组件导入到 src 文件夹之外的 mdx 文件中
- javascript - 我想在单击删除图像时显示弹出模式
- linux - 错误 CoreDNS 所需的最低内核版本为 4.14.35 (UEKR5)
- excel - Excel vba vlookup不返回值
- python - Pandas 系列 dt.period('M') 未转换为日期时间
- kdb - 从表中选择列表中的列
- java - 如何在 JScrollPane 的左上角添加组件?
- java - 如何拆分和打印一段 JSON/String?