Skip to content

Commit 4865661

Browse files
authored
Merge pull request #412 from jgilbert01/force-number-for-circuit-breaker
Force number for circuit breaker
2 parents 17ead99 + 4c4f99f commit 4865661

File tree

4 files changed

+89
-5
lines changed

4 files changed

+89
-5
lines changed

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.2",
3+
"version": "1.1.3",
44
"description": "Create stream processors with AWS Lambda functions.",
55
"keywords": [
66
"aws",

src/flavors/circuitbreaker.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const toUpdateRequest = (opt) => faulty((uow) => ({
1515
UUID: process.env.ESM_ID, // Ref: TriggerEventSourceMappingDynamodbEntitiesTable
1616
Enabled: uow.event.alarmData.state.value !== 'ALARM',
1717
BatchSize: uow.event.alarmData.state.value === 'INSUFFICIENT_DATA'
18-
? 1 : process.env.BATCH_SIZE || 100,
18+
? 1 : Number(opt.circuitBreakerMaxBatchSize)
19+
|| Number(process.env.CIRCUIT_BREAKER_MAX_BATCH_SIZE)
20+
|| Number(process.env.BATCH_SIZE)
21+
|| 100,
1922
},
2023
}));

test/unit/flavors/circuitbreaker.test.js

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'mocha';
22
import { expect } from 'chai';
33
import sinon from 'sinon';
44

5-
import { initialize } from '../../../src';
5+
import { initialize, initializeFrom } from '../../../src';
66

77
import { fromAlarm } from '../../../src/from/cw';
88

@@ -125,4 +125,85 @@ describe('flavors/circuitbreaker.js', () => {
125125
})
126126
.done(done);
127127
});
128+
129+
it('should enable event source mapping with batch size from opt)', (done) => {
130+
const rules = [
131+
{
132+
id: 'circuitBreaker',
133+
flavor: circuitBreaker,
134+
circuitBreakerMaxBatchSize: '10',
135+
},
136+
];
137+
const event = {
138+
source: 'aws.cloudwatch',
139+
alarmArn:
140+
'arn:aws:cloudwatch:us-east-1:444455556666:alarm:lambda-demo-metric-alarm',
141+
accountId: '444455556666',
142+
time: '2023-08-04T12:36:15.490+0000',
143+
region: 'us-east-1',
144+
alarmData: {
145+
alarmName: 'lambda-demo-metric-alarm',
146+
state: {
147+
value: 'OK',
148+
},
149+
previousState: {
150+
value: 'INSUFFICIENT_DATA',
151+
},
152+
},
153+
};
154+
155+
initialize({
156+
...initializeFrom(rules),
157+
})
158+
.assemble(fromAlarm(event), false)
159+
.collect()
160+
// .tap((collected) => console.log(JSON.stringify(collected, null, 2)))
161+
.tap((collected) => {
162+
expect(collected.length).to.equal(1);
163+
expect(collected[0].pipeline).to.equal('circuitBreaker');
164+
expect(collected[0].updateRequest).to.deep.equal({
165+
UUID: 'a092f90d-9948-4964-95b5-32c46093f734',
166+
Enabled: true,
167+
BatchSize: 10,
168+
});
169+
})
170+
.done(done);
171+
});
172+
it('should enable event source mapping and force Number type for env var of CIRCUIT_BREAKER_MAX_BATCH_SIZE', (done) => {
173+
process.env.CIRCUIT_BREAKER_MAX_BATCH_SIZE = '10';
174+
const event = {
175+
source: 'aws.cloudwatch',
176+
alarmArn:
177+
'arn:aws:cloudwatch:us-east-1:444455556666:alarm:lambda-demo-metric-alarm',
178+
accountId: '444455556666',
179+
time: '2023-08-04T12:36:15.490+0000',
180+
region: 'us-east-1',
181+
alarmData: {
182+
alarmName: 'lambda-demo-metric-alarm',
183+
state: {
184+
value: 'OK',
185+
},
186+
previousState: {
187+
value: 'INSUFFICIENT_DATA',
188+
},
189+
},
190+
};
191+
192+
initialize({
193+
circuitBreaker,
194+
})
195+
.assemble(fromAlarm(event), false)
196+
.collect()
197+
// .tap((collected) => console.log(JSON.stringify(collected, null, 2)))
198+
.tap((collected) => {
199+
expect(collected.length).to.equal(1);
200+
expect(collected[0].pipeline).to.equal('circuitBreaker');
201+
expect(collected[0].updateRequest).to.deep.equal({
202+
UUID: 'a092f90d-9948-4964-95b5-32c46093f734',
203+
Enabled: true,
204+
BatchSize: 10,
205+
});
206+
})
207+
.done(done);
208+
});
128209
});

0 commit comments

Comments
 (0)