Skip to content

Commit 420d280

Browse files
author
John Gilbert
committed
enabled pipelines env var
1 parent dc8c3c5 commit 420d280

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/pipelines/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@ export const initializeFrom = (rules) => rules.reduce(
4949
);
5050

5151
const assemble = (opt) => (head, includeFaultHandler = true) => {
52-
const disabledPipelines = process.env.DISABLED_PIPELINES?.split(',');
52+
const enabledPipelines = (opt.ENABLED_PIPELINES || process.env.ENABLED_PIPELINES)?.split(',');
53+
const disabledPipelines = (opt.DISABLED_PIPELINES || process.env.DISABLED_PIPELINES)?.split(',');
5354
const keys = Object.keys(thePipelines)
54-
.filter((k) => !disabledPipelines?.includes(k));
55+
.filter((k) => !disabledPipelines?.includes(k))
56+
.filter((k) =>
57+
!enabledPipelines || enabledPipelines.length === 0
58+
|| enabledPipelines.includes(k));
5559

5660
debug('assemble: %j', keys);
5761

test/unit/pipelines/pipelines.test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ import Connector from '../../../src/connectors/eventbridge';
1212
describe('pipelines/index.js', () => {
1313
beforeEach(() => {
1414
sinon.stub(Connector.prototype, 'putEvents').resolves({ FailedEntryCount: 0 });
15+
delete process.env.ENABLED_PIPELINES;
1516
delete process.env.DISABLED_PIPELINES;
1617
});
17-
afterEach(sinon.restore);
18+
afterEach(() => {
19+
delete process.env.ENABLED_PIPELINES;
20+
delete process.env.DISABLED_PIPELINES;
21+
sinon.restore();
22+
});
1823

1924
it('should invoke all pipelines', (done) => {
2025
let counter = 0;
@@ -46,6 +51,36 @@ describe('pipelines/index.js', () => {
4651
.done(done);
4752
});
4853

54+
it('should only run enabled pipelines - string', (done) => {
55+
process.env.ENABLED_PIPELINES = 'p1,p1b';
56+
let counter = 0;
57+
58+
const count = (uow) => {
59+
uow.counter = counter++; // eslint-disable-line no-plusplus
60+
return uow;
61+
};
62+
63+
const events = toKinesisRecords([{
64+
type: 't1',
65+
}]);
66+
67+
initialize({
68+
p1: (opt) => (s) => s.map(count),
69+
p1a: (opt) => (s) => s.map(count),
70+
p1b: (opt) => (s) => s.map(count),
71+
})
72+
.assemble(fromKinesis(events), false)
73+
.collect()
74+
.tap((collected) => {
75+
// console.log(JSON.stringify(collected, null, 2));
76+
expect(collected.length).to.equal(2);
77+
expect(counter).to.equal(2);
78+
expect(collected[0].pipeline).to.equal('p1b');
79+
expect(collected[1].pipeline).to.equal('p1');
80+
})
81+
.done(done);
82+
});
83+
4984
it('should ignore disabled pipelines - string', (done) => {
5085
process.env.DISABLED_PIPELINES = 'p1a';
5186
let counter = 0;

0 commit comments

Comments
 (0)