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

Faster initial poll for script responses #13097

Closed
candlerb opened this issue Jul 5, 2023 · 2 comments · Fixed by #13202
Closed

Faster initial poll for script responses #13097

candlerb opened this issue Jul 5, 2023 · 2 comments · Fixed by #13202
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application

Comments

@candlerb
Copy link
Contributor

candlerb commented Jul 5, 2023

NetBox version

v3.5.4

Feature type

Change to existing functionality

Proposed functionality

One of the downsides of scripts now being run as background tasks, with the results being polled, is that even a trivial script takes 5 seconds to produce a response.

e.g. even a simple script like this, still takes 5 seconds before its result is shown in the UI:

image

I propose that either:

  • the first poll is done 1 second after the job is submitted, and then 5 seconds thereafter (I expect that to be a very simple change)
  • the first few polls are done at 0.5 and 1 second intervals, after which it reverts to 5 seconds

Some sort of COMET / long-poll / server-sent event would clearly be a better solution, so that the result is returned as soon as it's available, but that would more work to implement.

Use case

When scripts are being used to automate data entry tasks, a 5 second delay on every form submission is long enough to become annoying quickly.

Database changes

None

External dependencies

None

@candlerb candlerb added the type: feature Introduction of new functionality to the application label Jul 5, 2023
@kkthxbye-code
Copy link
Contributor

One of the downsides of scripts now being run as background tasks, with the results being polled, is that even a trivial script takes 5 seconds to produce a response.

Scripts have always been run as background tasks.

The reason for the change in polling is this PR that changed the script result page to use HTMX.

#8130

As can be seen here, it just polls every 5 seconds:

https://github.com/netbox-community/netbox/blame/07ae7c8a6e04ecc6e641044330fd4d03e4997252/netbox/templates/extras/script_result.html#L50

The old system had a backoff timer, so for each request the interval would increase by 1 second until the interval was 10 seconds. Not sure if that's possible with HTMX, but the timer could probably be lowered regardless.

@candlerb
Copy link
Contributor Author

candlerb commented Jul 5, 2023

Thanks. Doc suggests hx-trigger="load delay:0.5s, load delay:1s, load delay:2s, every 5s" - which appears to work. Reducing 5s to 3s or 2s would be reasonable too IMO.

Alternatively, since the template has {% if not job.completed %}, there could be a short delay server-side before re-fetching the job and rendering the page.

P.S. There appears to be the same issue for reports

@DanSheps DanSheps added the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation label Jul 11, 2023
@abhi1693 abhi1693 self-assigned this Jul 13, 2023
@abhi1693 abhi1693 added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Jul 13, 2023
jeremystretch pushed a commit that referenced this issue Jul 27, 2023
* adds faster polling for scripts and reports #13097

* changes as per review
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants