Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(main): write the main control flow in an async function #129

Merged
merged 4 commits into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/__tests__/npm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('getDownloads()', () => {
expect(angular).toBeGreaterThan(1900000);
expect(angular).toBeLessThan(3000000);

expect(holmes).toBeGreaterThan(250);
expect(holmes).toBeGreaterThan(200);
expect(holmes).toBeLessThan(550);
});

Expand Down
24 changes: 15 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@ const { index: mainIndex, client } = createAlgoliaIndex(c.indexName);
const { index: bootstrapIndex } = createAlgoliaIndex(c.bootstrapIndexName);
const stateManager = createStateManager(mainIndex);

Promise.resolve()
.then(() => setSettings(bootstrapIndex))
.then(() => stateManager.check())
.then(bootstrap)
.then(() => stateManager.get())
.then(replicate)
.then(() => stateManager.get())
.then(watch)
.catch(error);
async function main() {
// first we make sure the bootstrap index has the correct settings
await setSettings(bootstrapIndex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why setSettings on the bootstrap index?

// then we run the bootstrap
// after a bootstrap is done, it's moved to main (with settings)
// if it was already finished, we will set the settings on the main index
await bootstrap(await stateManager.check());
// then we figure out which updates we missed since
// the last time main index was updated
await replicate(await stateManager.get());
// then we watch 👀 for all changes happening in the ecosystem
await watch(await stateManager.get());
}

main().catch(error);

async function setSettings(index) {
await index.setSettings(c.indexSettings);
Expand Down