Skip to content

Commit 00346af

Browse files
authored
Merge pull request #428 from jgilbert01/issue-multiple-cursors
Issue with job flavor handling multiple cursors in single lambda invocation
2 parents 78751c7 + 503bee9 commit 00346af

4 files changed

Lines changed: 344 additions & 29 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aws-lambda-stream",
3-
"version": "1.1.14",
3+
"version": "1.1.15",
44
"description": "Create stream processors with AWS Lambda functions.",
55
"keywords": [
66
"aws",

src/flavors/job.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import _ from 'highland';
21
import {
32
printStartPipeline, printEndPipeline,
43
faulty, faultyAsyncStream, faultify,
54
splitObject, encryptEvent,
5+
compact,
66
} from '../utils';
77
import {
88
scanSplitDynamoDB, querySplitDynamoDB, queryAllDynamoDB, batchGetDynamoDB,
@@ -132,35 +132,36 @@ export const toCursorUpdateRequest = (rule) => faulty((uow) => ({
132132
}));
133133

134134
export const flushCursor = (rule) => (s) => {
135-
let lastUow;
136-
137-
const cursorStream = () => _([lastUow])
138-
.map(toCursorUpdateRequest(rule))
139-
.through(updateDynamoDB({
140-
...rule,
141-
updateRequestField: 'cursorUpdateRequest',
142-
updateResponseField: 'cursorUpdateResponse',
143-
}));
135+
const {
136+
// By default group on a stringified version of the full key. If the key structure
137+
// differs in a users particular implementation or they want to group by something
138+
// else they can simply override this fn in their rule.
139+
cursorKeyFn = (uow) => `pk:${uow.event.raw.new.pk}|sk:${uow.event.raw.new.sk}`,
140+
} = rule;
144141

145142
/* istanbul ignore else */
146143
if (rule.toCursorUpdateRequest) {
147144
return s
148-
.consume((err, x, push, next) => {
149-
/* istanbul ignore if */
150-
if (err) {
151-
push(err);
152-
next();
153-
} else if (x === _.nil) {
154-
if (lastUow) {
155-
next(cursorStream());
156-
} else {
157-
push(null, x);
158-
}
159-
} else {
160-
lastUow = x;
161-
push(null, x);
162-
next();
163-
}
145+
.through(compact({
146+
...rule,
147+
compact: {
148+
group: (uow) => cursorKeyFn(uow),
149+
},
150+
}))
151+
.map(toCursorUpdateRequest(rule))
152+
.through(updateDynamoDB({
153+
...rule,
154+
updateRequestField: 'cursorUpdateRequest',
155+
updateResponseField: 'cursorUpdateResponse',
156+
}))
157+
// Maintains backwards compatibility with how this used to manipulate the UOWs,
158+
// duping the last uow.
159+
.flatMap((uow) => {
160+
const { batch, ...lastUow } = uow;
161+
return [
162+
...batch,
163+
lastUow,
164+
];
164165
});
165166
} else {
166167
return s;

0 commit comments

Comments
 (0)