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

fix: kill process regurlarly, for cache and bootstrap #412

Merged
merged 3 commits into from
Aug 25, 2019
Merged
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@ import * as watch from './watch.js';

log.info('🗿 npm ↔️ Algolia replication starts ⛷ 🐌 🛰');

const KILL_PROCESS_EVERY_MS = 12 * 60 * 60 * 1000; // every 12 hours

/**
* Main process
* - Bootstrap: will index the whole list of packages (if needed)
* - Watch : will process update in real time
*/
async function main() {
const start = Date.now();

// We schedule to kill the process:
// - reset cache
// - maybe retrigger bootstrap
setInterval(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
setInterval(() => {
setTimeout(() => {

Does this have an impact on perf, I've heard other times long-running timers can take up much more memory than expected, or will it be fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to find info about this, I think the way nodejs is managing the even loop is making it trivial (or at least consistant) wether it's long or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

NB: you can have up to 25days (32bit) of timeout, so they probably handle that fine

log.info('👋 Scheduled process cleaning');
// eslint-disable-next-line no-process-exit
process.exit(0);
}, KILL_PROCESS_EVERY_MS);

// first we make sure the bootstrap index has the correct settings
log.info('💪 Setting up Algolia');
const {
Expand Down