Skip to content

Commit 3f8f3ef

Browse files
authored
fix(runtime): add mongodb stream reconnect (#1276)
* feat: fix runtime * feat: add stream reconnect * fix: fix work case
1 parent c7469d3 commit 3f8f3ef

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

runtimes/nodejs/src/support/db-change-stream.ts

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ export class DatabaseChangeStream {
2222
stream.on('change', async (_change) => {
2323
this.updateEnvironments()
2424
})
25+
26+
stream.on('close', () => {
27+
logger.info('Conf collection change stream closed.')
28+
setTimeout(() => {
29+
logger.info('Reconnecting conf collection change stream...')
30+
this.watchConf()
31+
}, 3000)
32+
})
33+
2534
}
2635

2736
private static async updateEnvironments() {

runtimes/nodejs/src/support/function-engine/cache.ts

+8
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ export class FunctionCache {
7171
}
7272
}
7373
})
74+
75+
stream.on('close', () => {
76+
logger.error('Cloud function change stream closed')
77+
setTimeout(() => {
78+
logger.info('Reconnecting cloud function change stream...')
79+
this.streamChange()
80+
}, 3000)
81+
})
7482
}
7583

7684
/**

0 commit comments

Comments
 (0)