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

Add support for filesystem polling #1176

Merged
merged 8 commits into from
Sep 3, 2024
Merged

Add support for filesystem polling #1176

merged 8 commits into from
Sep 3, 2024

Conversation

aomarks
Copy link
Member

@aomarks aomarks commented Aug 31, 2024

Adds WIREIT_WATCH_STRATEGY and WIREIT_WATCH_POLL_MS environment variables which can be used to switch filesystem detection from event-based to polling:

export WIREIT_WATCH_STRATEGY=poll
export WIREIT_WATCH_POLL_MS=<a number if you don't like the default of 500>

Currently this just sets the chokidar usePolling and interval options. It might be nice to actually bypass chokidar entirely so that this option can be used to bypass any potential issues with chokidar generally, but it's slightly complex (just re-running the script on an interval isn't great, because of scripts which aren't set up well for caching).

This is published as v0.14.9-pre.1. Would be great to hear from @peschee if this is a useful workaround for the OOM errors they have been seeing in their project.

@peschee
Copy link
Contributor

peschee commented Aug 31, 2024

So cool @aomarks, will give this a spin on Monday.

CHANGELOG.md Outdated Show resolved Hide resolved
@peschee
Copy link
Contributor

peschee commented Sep 2, 2024

@aomarks I gave this a go yesterday and in my first tests, using WIREIT_WATCH_STRATEGY=poll I'm not experiencing any OOM issues anymore. I will keep an eye out the next few days, but from where I stand, this looks like a great addition to me!

@aomarks aomarks marked this pull request as ready for review September 2, 2024 06:09
*/
function readWatchConfigFromEnv(): Options['watch'] {
switch (process.env['WIREIT_WATCH_STRATEGY']) {
case 'event':
Copy link
Collaborator

Choose a reason for hiding this comment

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

Style nit: I definitely prefer avoid fall-through myself. Would this be easier as an if/else statement?

Copy link
Member Author

Choose a reason for hiding this comment

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

This whole file (and other files) uses this style of switching on state. We're doing exhaustive checking for every state for every transition. I actually kinda like using fallthrough here, it's just the most concise way to write out all the permutations.

if (intervalStr) {
const parsed = Number(intervalStr);
if (Number.isNaN(parsed) || parsed <= 0) {
console.error(
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is continuing to operate with the fallback value, should this be console.warn() instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Both go to stderr, but in some configurations warnings might get filtered out? I guess because it's definitely something wrong, I think it should be an error to maximize the chance of somebody seeing it.

};
}
default: {
console.error(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

@aomarks aomarks enabled auto-merge (squash) September 3, 2024 18:14
@aomarks aomarks merged commit 9c64d90 into main Sep 3, 2024
20 checks passed
@aomarks aomarks deleted the watch-poll branch September 3, 2024 18:35
@peschee
Copy link
Contributor

peschee commented Sep 3, 2024

💪🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants