-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
57 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 16 additions & 10 deletions
26
services/authoring/src/repositories/git-continuous-updater.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
import { Observable } from 'rxjs'; | ||
import { concat, defer, EMPTY } from 'rxjs'; | ||
import { catchError, delay, distinctUntilChanged, repeat, tap } from 'rxjs/operators'; | ||
import logger from '../utils/logger'; | ||
const { CONTINUOUS_UPDATER_INTERVAL } = require('../constants'); | ||
|
||
export default { | ||
onUpdate(gitTransactionManager) { | ||
const updateRepo$ = Observable.defer(async () => { | ||
const updateRepo$ = defer(async () => { | ||
await gitTransactionManager.read(async (gitRepo) => await gitRepo.fetch()); | ||
return await gitTransactionManager.write(async (gitRepo) => await gitRepo.mergeMaster()); | ||
}); | ||
}).pipe( | ||
catchError((err) => { | ||
logger.error({ err }, 'Error pulling changes in git repo'); | ||
return EMPTY; | ||
}), | ||
); | ||
|
||
return updateRepo$ | ||
.do(null, (err) => logger.error({ err }, 'Error pulling changes in git repo')) | ||
.catch((_) => Observable.empty()) | ||
.concat(Observable.empty().delay(CONTINUOUS_UPDATER_INTERVAL)) | ||
.repeat() | ||
.distinctUntilChanged() | ||
.do((sha) => logger.info({ sha }, 'Updated git repo')); | ||
const delayComplete$ = EMPTY.pipe(delay(CONTINUOUS_UPDATER_INTERVAL)); | ||
|
||
return concat(updateRepo$, delayComplete$).pipe( | ||
repeat(), | ||
distinctUntilChanged(), | ||
tap((sha) => logger.info({ sha }, 'Updated git repo')), | ||
); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters