From 83fe4dd8f0322513a21545e709c12e65538dff78 Mon Sep 17 00:00:00 2001 From: Zeb Taylor <64664378+iztaylor@users.noreply.github.com> Date: Mon, 28 Sep 2020 13:13:14 -0700 Subject: [PATCH 1/2] Makes async-kinesis-client DynamoDB checkpoint table compatible with aioboto3 context manager requirement. --- src/async_kinesis_client/dynamodb.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/async_kinesis_client/dynamodb.py b/src/async_kinesis_client/dynamodb.py index 406b7d1..ca0e2b8 100644 --- a/src/async_kinesis_client/dynamodb.py +++ b/src/async_kinesis_client/dynamodb.py @@ -20,20 +20,19 @@ class DynamoDB: DEFAULT_MAX_RETRIES = 5 - def __init__(self, table_name, shard_id, max_retries=DEFAULT_MAX_RETRIES, host_key=None): + def __init__(self, table, shard_id, max_retries=DEFAULT_MAX_RETRIES, host_key=None): """ Initialize DynamoDB - :param table_name: DynamoDB table name + :param table: DynamoDB table object :param shard_id: ShardId as returned by kinesis client :param max_retries: Max retries for communicating with DynamoDB :param host_key: Key to identify reader. If no key provided, defaults to FQDN """ - self.table_name = table_name self.shard_id = shard_id self.shard = {} self.host_key = host_key or socket.getfqdn() - self.lock_holding_time = None - table = aioboto3.resource('dynamodb').Table(self.table_name) + self.lock_holding_time = 0 + self.table_name = table.table_name self.dynamo_table = RetriableDynamoDB(table=table, retries=max_retries, retry_sleep_time=1) async def checkpoint(self, seq): From 0d98df34ca3f99e355860969c26f8d1f5fc19046 Mon Sep 17 00:00:00 2001 From: Zeb Taylor <64664378+iztaylor@users.noreply.github.com> Date: Mon, 28 Sep 2020 13:14:12 -0700 Subject: [PATCH 2/2] Makes async-kinesis-client DynamoDB checkpoint table compatible with aioboto3 context manager requirement. --- src/async_kinesis_client/kinesis_consumer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/async_kinesis_client/kinesis_consumer.py b/src/async_kinesis_client/kinesis_consumer.py index c0b9f17..5ccdc92 100644 --- a/src/async_kinesis_client/kinesis_consumer.py +++ b/src/async_kinesis_client/kinesis_consumer.py @@ -351,7 +351,7 @@ async def get_shard_lock(self, shard_id): # obtain lock if we don't have it, or refresh if we're already holding it if dynamodb is None: dynamodb = DynamoDB( - table_name=self.checkpoint_table, + table=self.checkpoint_table, shard_id=shard_id, host_key=self.host_key )