-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Stop polling based on the response #106
Comments
Hey, @thiagorp, thanks for submitting the issue! The idea sounds interesting to me! You are right about the polling, it either goes on until you refresh the page, or you set it up to be turned off by an event. I'm not sure how to build this, stopping polling based on the request response might be tricky. Are you able to stop polling by initiating an event to stop polling maybe? We could add an option to stop polling if an event is dispatched from somewhere (does not have to be a user event like it is now): <%= render_async comments_path,
toggle: { event: 'stop-polling-event' }, # you would have to dispatch this from your JS code
interval: 2000 %> # poll for comments_path every 2 seconds Then, you could use a default event or emit your own when render_async finishes each request. Catch that event, parse the response (we'd have to add response object to the event that is dispatched after request succeeds) and then emit another event to stop polling. WDYT? |
I wanted to do exactly what @thiagorp wants to do. This is the workaround I came up with so that I could use the current version and keep my project moving. The user does have to manually start the polling, but when the task is complete I redirect the user and stop the polling.
I'm a bit rusty with the javascript, tried to fire the click programmatically so the user didn't need to start the polling. However this caused the polling to go crazy, not sure why.
The idea presented by @nikolalsvk would be ideal longer term. ** Sidenote - one thing I realized is that Turbolinks can mess up the page properly polling. In my link_to tags I had to turn Turbolinks off **
|
Hey, @benr75, thanks for the suggestion that you've been using! I think some people will find it useful until we get some solution on the way. BTW, for your sidenote about Turbolinks, have you tried setting the config variable like described in the README maybe? It could save you some extra code :) |
I think #118 is related - the use case would be:
The polling continues forever even when the server replies with an error status. Maybe an easy solution would be an option to stop polling on an error status code? |
This sounds good, we could add an option to stop polling on specific error code. Something like |
I implemented some code that sets up |
#106 Add polling control start/stop events
Suggest closing this issue. The 'async-stop' event works great for stopping the polling when a background job is completed, or based upon some other status. |
It would be nice to provide some kind of an example of how to do this with the response of the polling request. I think we can't do it right now because we don't return response data in the default events (like the What you suggested here:
might work, but it depends on factors we can't control. For example, what if a user doesn't have an indicator like a finished background job to stop the polling? WDYT, @vanboom? |
Since In my app, I monitor the progress of a Sidekiq worker using polling that renders a JS partial. When the job is complete or on any other error, my logic triggers Something like this in the rendered view (e.g. jobs/show.js.erb): <% if @job.complete? %>
$("#<%= dom_id(@job, :polling)%>").trigger("async-stop");
<% end %> |
Right, the idea itself sounds pretty complicated from what we have right now. I want to keep the issue open so it attracts new ideas we can have about this. What you did is great and we're thankful for it, it would be even better if we had some kind of example of how this |
First of all, thanks for the work on the lib :)
I have the following situation: I'm running a script in the background and want to poll for the logs. The problem I see with the current polling approach is that it never stops, only if some user-initiated event happens. But that's not a good experience in this case. Ideally, the polling should stop when the server returns that the script is done running.
Is it possible to solve it somehow?
The text was updated successfully, but these errors were encountered: