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 --timeout option to reload after website has fully built #3

Open
Evidlo opened this issue Jul 8, 2019 · 6 comments
Open

Add --timeout option to reload after website has fully built #3

Evidlo opened this issue Jul 8, 2019 · 6 comments

Comments

@Evidlo
Copy link

Evidlo commented Jul 8, 2019

I'm using httpwatcher to automatically reload my browser while authoring content with a static website generator. Unfortunately, the website generator does a full rebuild of the website when changes are detected, which can cause httpwatcher to trigger a reload before the generator is finished rebuilding or even trigger httpwatcher multiple times in one rebuild.

This could be solved pretty simply if httpwatcher had a --timeout N option whereby an N millisecond countdown is started when a change is detected before httpwatcher starts to reload the page.

Is this equivalent to watcher_inverval? In any case, it's not yet available as a flag.

@blackdaemon
Copy link

This is still a problem. I wanted to use httpwatcher on RaspberryPI and since the files are stored on sdcard and any edit and save of the file with vim takes some time (vim probably first removes the original file and then renames the working copy of the file .swp), the httpwatcher will error with 404.

@jobveldhuis
Copy link
Collaborator

Sounds like a good feature to add. Does any one of you want to create a PR, or should I take this upon myself? @blackdaemon @Evidlo

@Evidlo
Copy link
Author

Evidlo commented May 19, 2021

@jobveldhuis Go ahead. I actually implemented this to a degree a while ago, but the files are gone now.

@jobveldhuis
Copy link
Collaborator

@Evidlo Please check the latest version of the dev branch and see whether or not this is the use case you had in mind. You are now able to use: --interval <number> to increase or decrease the maximum polling of the server.

@Evidlo
Copy link
Author

Evidlo commented May 25, 2021

@jobveldhuis The behavior I'm proposing is just subtly different from a simple reload interval. I came up with a contrived example to show how httpwatcher can actually miss file change events if implemented this way:

Current behavior (with --interval 1):

0.00s file changed   <- reload
0.25s file changed
0.50s file changed
0.75s file changed
1.00s file changed   <- reload
1.25s file changed
1.50s file changed

As you can see, the last two file change events are not picked up by httpwatcher. If we instead wait for a period of no activity before reloading, we can catch these events:

Proposed behavior (with --interval 1):

0.00s file changed
0.25s file changed
0.50s file changed
0.75s file changed
1.00s file changed
1.25s file changed
1.50s file changed
1.75s
2.00s
2.25s
2.50s                <- reload

So basically, a file change event should start/reset a timer which then triggers the page reload.

I think this would be implemented with tornado's call_later function with a callback to trigger the page reload.

@jobveldhuis
Copy link
Collaborator

So you are proposing a delay of some kind? Sounds good, I will look into this tonight!

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

No branches or pull requests

3 participants