@teamvibe/poller 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/session-store.js +18 -11
- package/package.json +1 -1
package/dist/session-store.js
CHANGED
|
@@ -106,26 +106,33 @@ export async function acquireSessionLock(threadId, workspacePath) {
|
|
|
106
106
|
// Session is idle/waiting - try to acquire lock
|
|
107
107
|
const newLockToken = generateLockToken();
|
|
108
108
|
const now = Date.now();
|
|
109
|
+
const hasOldToken = existingSession.lock_token != null;
|
|
110
|
+
const conditionExpression = hasOldToken
|
|
111
|
+
? '#status IN (:idle, :waiting) AND (lock_token = :oldToken OR attribute_not_exists(lock_token))'
|
|
112
|
+
: '#status IN (:idle, :waiting) AND attribute_not_exists(lock_token)';
|
|
113
|
+
const expressionValues = {
|
|
114
|
+
':processing': 'processing',
|
|
115
|
+
':idle': 'idle',
|
|
116
|
+
':waiting': 'waiting_for_input',
|
|
117
|
+
':newToken': newLockToken,
|
|
118
|
+
':now': now,
|
|
119
|
+
':one': 1,
|
|
120
|
+
':ttl': calculateTTL(),
|
|
121
|
+
};
|
|
122
|
+
if (hasOldToken) {
|
|
123
|
+
expressionValues[':oldToken'] = existingSession.lock_token;
|
|
124
|
+
}
|
|
109
125
|
try {
|
|
110
126
|
await createDocClient().send(new UpdateCommand({
|
|
111
127
|
TableName: getTableName(),
|
|
112
128
|
Key: buildKey(threadId),
|
|
113
129
|
UpdateExpression: 'SET #status = :processing, lock_token = :newToken, last_activity = :now, message_count = message_count + :one, #ttl = :ttl',
|
|
114
|
-
ConditionExpression:
|
|
130
|
+
ConditionExpression: conditionExpression,
|
|
115
131
|
ExpressionAttributeNames: {
|
|
116
132
|
'#status': 'status',
|
|
117
133
|
'#ttl': 'ttl',
|
|
118
134
|
},
|
|
119
|
-
ExpressionAttributeValues:
|
|
120
|
-
':processing': 'processing',
|
|
121
|
-
':idle': 'idle',
|
|
122
|
-
':waiting': 'waiting_for_input',
|
|
123
|
-
':newToken': newLockToken,
|
|
124
|
-
':oldToken': existingSession.lock_token,
|
|
125
|
-
':now': now,
|
|
126
|
-
':one': 1,
|
|
127
|
-
':ttl': calculateTTL(),
|
|
128
|
-
},
|
|
135
|
+
ExpressionAttributeValues: expressionValues,
|
|
129
136
|
}));
|
|
130
137
|
const updatedSession = {
|
|
131
138
|
...existingSession,
|