Faster initial poll for script responses #8301

Closed
opened 2025-12-29 20:35:06 +01:00 by adam · 2 comments
Owner

Originally created by @candlerb on GitHub (Jul 5, 2023).

Originally assigned to: @abhi1693 on GitHub.

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

Originally created by @candlerb on GitHub (Jul 5, 2023). Originally assigned to: @abhi1693 on GitHub. ### 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](https://github.com/netbox-community/netbox/assets/44789/a583968a-fbc1-4578-9274-aac81a2b9419) 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
adam added the status: acceptedtype: feature labels 2025-12-29 20:35:06 +01:00
adam closed this issue 2025-12-29 20:35:06 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Jul 5, 2023):

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.

https://github.com/netbox-community/netbox/pull/8130

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

07ae7c8a6e/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.

@kkthxbye-code commented on GitHub (Jul 5, 2023): > 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. https://github.com/netbox-community/netbox/pull/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.
Author
Owner

@candlerb commented on GitHub (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

@candlerb commented on GitHub (Jul 5, 2023): Thanks. [Doc](https://htmx.org/attributes/hx-trigger/) 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
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8301