Skip to content

Commit

Permalink
Merge pull request #117 from lifion/bugfix/add-shards-to-enhanced-con…
Browse files Browse the repository at this point in the history
…sumers

Add shards on update
  • Loading branch information
Mackenzie Turner authored Apr 29, 2019
2 parents f814f18 + 9d4a7d7 commit fab8c17
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions lib/state-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,23 +459,39 @@ class StateStore {
}

async lockStreamConsumer(consumerName, version) {
const { client, consumerGroup, consumerId, logger, streamName } = internal(this);
const {
client,
consumerGroup,
consumerId,
logger,
streamName,
useAutoShardAssignment
} = internal(this);

try {
await client.update({
ConditionExpression: `#a.#b.#d = :z`,
ExpressionAttributeNames: {
'#a': 'enhancedConsumers',
'#b': consumerName,
'#c': 'isUsedBy',
'#d': 'version'
},
ExpressionAttributeValues: {
':x': consumerId,
':y': generate(),
':z': version
},
ExpressionAttributeNames: Object.assign(
{
'#a': 'enhancedConsumers',
'#b': consumerName,
'#c': 'isUsedBy',
'#d': 'version'
},
!useAutoShardAssignment && { '#e': 'shards' }
),
ExpressionAttributeValues: Object.assign(
{
':x': consumerId,
':y': generate(),
':z': version
},
!useAutoShardAssignment && { ':e': {} }
),
Key: { consumerGroup, streamName },
UpdateExpression: `SET #a.#b.#c = :x, #a.#b.#d = :y`
UpdateExpression: `SET #a.#b.#c = :x, #a.#b.#d = :y${
!useAutoShardAssignment ? ', #a.#b.#e = if_not_exists(#a.#b.#e, :e)' : ''
}`
});
return true;
} catch (err) {
Expand Down

0 comments on commit fab8c17

Please sign in to comment.