Skip to content

Commit

Permalink
feat(process): redo bootstrap after X amount of time
Browse files Browse the repository at this point in the history
fixes #20

In the 'watch' step, I get the state after each iteration, then if now - last time bootstrap was done is more than the time to redo the bootstrap, the settings

```js
stateManager.set({
  seq: 0,
  bootstrapDone: false,
});
```

are being set, which *should* make the bootstrap start over.
  • Loading branch information
Haroenv committed Apr 29, 2017
1 parent f0c3b27 commit a79d999
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const defaultConfig = {
indexName: 'npm-search',
replicateConcurrency: 10,
bootstrapConcurrency: 100,
timeToRedoBootstrap: 604800000 /* one week */,
seq: null,
indexSettings: {
searchableAttributes: [
Expand All @@ -20,7 +21,6 @@ const defaultConfig = {
'owners.name',
],
attributesForFaceting: [
'onlyFilter(name)' /* to be removed when frontend concatenates */,
'onlyFilter(concatenatedName)' /* optionalFacetFilters to boost the name */,
'keywords',
],
Expand Down
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function bootstrap(state) {
log.info('⛷ Bootstrap: done');
return stateManager.save({
bootstrapDone: true,
bootstrapLastDone: new Date().toISOString(),
});
}

Expand Down Expand Up @@ -179,6 +180,17 @@ function watch({ seq }) {
seq: change.seq,
})
)
.then(stateManager.get)
.then(({ bootstrapLastDone }) => {
const now = new Date();
const lastBootstrapped = new Date(bootstrapLastDone);
if (now - lastBootstrapped > c.timeToRedoBootstrap) {
stateManager.set({
seq: 0,
bootstrapDone: false,
});
}
})
.catch(reject);
});
changes.on('error', reject);
Expand Down

0 comments on commit a79d999

Please sign in to comment.