Skip to content

Commit 06d3059

Browse files
authored
Base iterator looses dynamic endpoints information on consecutive runs (#50)
1 parent 2c51c6c commit 06d3059

22 files changed

+187
-125
lines changed

backend/src/serverless/integrations/coordinators/devtoCoordinator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function devtoCoordinator(): Promise<void> {
1919
integrationId: integration.id,
2020
tenant: integration.tenantId.toString(),
2121
onboarding: false,
22-
state: { endpoint: '', page: '' },
22+
state: { endpoint: '', page: '', endpoints: [] },
2323
args: {},
2424
}
2525

backend/src/serverless/integrations/coordinators/discordCoordinator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function discordCoordinator(): Promise<void> {
1616
sleep: Math.floor(Math.random() * 1200),
1717
tenant: integration.tenantId.toString(),
1818
onboarding: false,
19-
state: { endpoint: '', page: '' },
19+
state: { endpoint: '', page: '', endpoints: [] },
2020
args: {
2121
guildId: integration.integrationIdentifier,
2222
channels: integration.settings.channels || [],

backend/src/serverless/integrations/coordinators/slackCoordinator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function slackCoordinator(): Promise<void> {
1616
sleep: 0,
1717
tenant: integration.tenantId.toString(),
1818
onboarding: false,
19-
state: { endpoint: '', page: '' },
19+
state: { endpoint: '', page: '', endpoints: [] },
2020
args: {
2121
channels: integration.settings.channels || [],
2222
},

backend/src/serverless/integrations/coordinators/twitterCoordinator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function twitterCoordinator(): Promise<void> {
1616
sleep: 0,
1717
tenant: integration.tenantId.toString(),
1818
onboarding: false,
19-
state: { endpoint: '', page: '' },
19+
state: { endpoint: '', page: '', endpoints: [] },
2020
args: {
2121
profileId: integration.integrationIdentifier,
2222
hashtags: integration.settings.hashtags,

backend/src/serverless/integrations/coordinators/twitterReachCoordinator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async function twitterReachCoordinator(): Promise<void> {
1515
sleep: 0,
1616
tenant: microservice.tenantId.toString(),
1717
onboarding: false,
18-
state: { endpoint: '', page: '' },
18+
state: { endpoint: '', page: '', endpoints: [] },
1919
args: {
2020
profileId: microservice.microserviceIdentifier,
2121
},

backend/src/serverless/integrations/iterators/__tests__/baseIteration.test.ts

Lines changed: 82 additions & 63 deletions
Large diffs are not rendered by default.

backend/src/serverless/integrations/iterators/__tests__/baseIteratorStatic.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@ describe('Integrations worker static tests', () => {
55
const endpoints = ['endpoint1', 'endpoint2', 'endpoint3']
66
describe('Get iterator tests', () => {
77
it('Should return the endpoints to iterate for a standard state', async () => {
8-
const state = { endpoint: 'endpoint2', page: 'here' }
8+
const state = { endpoint: 'endpoint2', page: 'here', endpoints: [] }
99
const iterator = BaseIterator.getEndPointsIterator(endpoints, state)
1010

1111
expect(iterator).toStrictEqual(['endpoint2', 'endpoint3'])
1212
})
1313

1414
it('Should return the endpoints to iterate for a state with no page', async () => {
15-
const state = { endpoint: 'endpoint2', page: '' }
15+
const state = { endpoint: 'endpoint2', page: '', endpoints: [] }
1616
const iterator = BaseIterator.getEndPointsIterator(endpoints, state)
1717

1818
expect(iterator).toStrictEqual(['endpoint2', 'endpoint3'])
1919
})
2020

2121
it('Should return the whole endpoints when the state is in the first endpoint with a page', async () => {
22-
const state = { endpoint: 'endpoint1', page: 'here' }
22+
const state = { endpoint: 'endpoint1', page: 'here', endpoints: [] }
2323
const iterator = BaseIterator.getEndPointsIterator(endpoints, state)
2424

2525
expect(iterator).toStrictEqual(endpoints)
2626
})
2727

2828
it('Should return the last endpoint when the state is in the last endpoint', async () => {
29-
const state = { endpoint: 'endpoint3', page: '' }
29+
const state = { endpoint: 'endpoint3', page: '', endpoints: [] }
3030
const iterator = BaseIterator.getEndPointsIterator(endpoints, state)
3131

3232
expect(iterator).toStrictEqual(['endpoint3'])
3333
})
3434

3535
it('Should throw an error when state.endpoint is not in endpoints', async () => {
36-
const state = { endpoint: 'endpoint4', page: '' }
36+
const state = { endpoint: 'endpoint4', page: '', endpoints: [] }
3737
try {
3838
BaseIterator.getEndPointsIterator(endpoints, state)
3939
} catch (error: any) {
@@ -48,17 +48,20 @@ describe('Integrations worker static tests', () => {
4848
const state = BaseIterator.initState(endpoints, {
4949
endpoint: '',
5050
page: '',
51+
endpoints: [],
5152
})
5253
expect(state).toStrictEqual({
5354
endpoint: 'endpoint1',
5455
page: '',
56+
endpoints: ['endpoint1', 'endpoint2', 'endpoint3'],
5557
})
5658
})
5759

5860
it('Should return the given state', async () => {
5961
const givenState = {
6062
endpoint: 'endpoint2',
6163
page: 'here',
64+
endpoints: [],
6265
}
6366
const state = BaseIterator.initState(endpoints, givenState)
6467
expect(state).toStrictEqual(givenState)

backend/src/serverless/integrations/iterators/__tests__/devtoIterator.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ async function getDevtoIterator(articles: DevtoArticle[]) {
7676
{
7777
endpoint: '',
7878
page: '',
79+
endpoints: [],
7980
},
8081
false,
8182
)

backend/src/serverless/integrations/iterators/__tests__/discordIterator.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ describe('Discord iterator tests', () => {
589589
'guild12345',
590590
'token12345',
591591
channels,
592-
{ endpoint: '', page: '' },
592+
{ endpoint: '', page: '', endpoints: [] },
593593
true,
594594
)
595595
const isOver = iter.integrationSpecificIsEndpointFinished('1', recentRecord)
@@ -605,7 +605,7 @@ describe('Discord iterator tests', () => {
605605
'guild12345',
606606
'token12345',
607607
channels,
608-
{ endpoint: '', page: '' },
608+
{ endpoint: '', page: '', endpoints: [] },
609609
true,
610610
)
611611
const isOver = iter.integrationSpecificIsEndpointFinished('4', recentRecord)
@@ -621,7 +621,7 @@ describe('Discord iterator tests', () => {
621621
'guild12345',
622622
'token12345',
623623
channels,
624-
{ endpoint: '', page: '' },
624+
{ endpoint: '', page: '', endpoints: [] },
625625
true,
626626
)
627627
const isOver = iter.integrationSpecificIsEndpointFinished('3', recentRecord)
@@ -637,7 +637,7 @@ describe('Discord iterator tests', () => {
637637
'guild12345',
638638
'token12345',
639639
channels,
640-
{ endpoint: '', page: '' },
640+
{ endpoint: '', page: '', endpoints: [] },
641641
true,
642642
)
643643
const isOver = iter.integrationSpecificIsEndpointFinished('1', oldRecord)
@@ -653,7 +653,7 @@ describe('Discord iterator tests', () => {
653653
'guild12345',
654654
'token12345',
655655
channels,
656-
{ endpoint: '', page: '' },
656+
{ endpoint: '', page: '', endpoints: [] },
657657
true,
658658
)
659659
const isOver = iter.integrationSpecificIsEndpointFinished('3', oldRecord)
@@ -669,7 +669,7 @@ describe('Discord iterator tests', () => {
669669
'guild12345',
670670
'token12345',
671671
channels,
672-
{ endpoint: '', page: '' },
672+
{ endpoint: '', page: '', endpoints: [] },
673673
true,
674674
)
675675
const isOver = iter.integrationSpecificIsEndpointFinished('4', oldRecord)
@@ -685,7 +685,7 @@ describe('Discord iterator tests', () => {
685685
'guild12345',
686686
'token12345',
687687
channels,
688-
{ endpoint: '', page: '' },
688+
{ endpoint: '', page: '', endpoints: [] },
689689
true,
690690
)
691691
const isOverGeneral = iter.isEndpointFinished('4', {}, [])

backend/src/serverless/integrations/iterators/__tests__/githubIterator.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ async function getGithubIterator(repos: Repos, options: IRepositoryOptions) {
3838
{
3939
endpoint: '',
4040
page: '',
41+
endpoints: [],
4142
},
4243
true,
4344
)

0 commit comments

Comments
 (0)