Enable webhooks for JobResults #6258

Closed
opened 2025-12-29 19:38:36 +01:00 by adam · 10 comments
Owner

Originally created by @kkthxbye-code on GitHub (Mar 24, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.1.9

Feature type

Change to existing functionality

Proposed functionality

Add the @extra_features('webhooks') to the JobResult model.

Use case

When triggering Netbox scripts via. the API it would be useful to be able to send a webhook when the status changes. This would prevent the need for polling the API for scripts with longer runtime.

Database changes

None

External dependencies

No response

Originally created by @kkthxbye-code on GitHub (Mar 24, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.1.9 ### Feature type Change to existing functionality ### Proposed functionality Add the @extra_features('webhooks') to the JobResult model. ### Use case When triggering Netbox scripts via. the API it would be useful to be able to send a webhook when the status changes. This would prevent the need for polling the API for scripts with longer runtime. ### Database changes None ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 19:38:36 +01:00
adam closed this issue 2025-12-29 19:38:36 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Mar 24, 2022):

I tried just adding @extras_features('webhooks') to the model, but it doesn't trigger webhooks. I'm sure there are some pre-requisites for using webhooks I'm not aware of. I wouldn't mind implementing if accepted and with a small pointer as to what is needed to make it work.

@kkthxbye-code commented on GitHub (Mar 24, 2022): I tried just adding `@extras_features('webhooks')` to the model, but it doesn't trigger webhooks. I'm sure there are some pre-requisites for using webhooks I'm not aware of. I wouldn't mind implementing if accepted and with a small pointer as to what is needed to make it work.
Author
Owner

@kkthxbye-code commented on GitHub (Apr 1, 2022):

Looking into this more, I guess JobResults would be to be changed to inherit from ChangeLoggedModel. Not sure how feasible that is or if it just works out of the box. The migration would make it a significant change I guess.

@kkthxbye-code commented on GitHub (Apr 1, 2022): Looking into this more, I guess JobResults would be to be changed to inherit from ChangeLoggedModel. Not sure how feasible that is or if it just works out of the box. The migration would make it a significant change I guess.
Author
Owner

@jeremystretch commented on GitHub (Apr 7, 2022):

I guess JobResults would be to be changed to inherit from ChangeLoggedModel

We can enable webhooks for the model separately, without having to inherit the other stuff ChangeLoggedModel provides.

@jeremystretch commented on GitHub (Apr 7, 2022): > I guess JobResults would be to be changed to inherit from ChangeLoggedModel We can enable webhooks for the model separately, without having to inherit the other stuff ChangeLoggedModel provides.
Author
Owner

@github-actions[bot] commented on GitHub (Jun 8, 2022):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Jun 8, 2022): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Jul 8, 2022):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Jul 8, 2022): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Author
Owner

@jeremystretch commented on GitHub (Feb 28, 2023):

@kkthxbye-code would we want to evaluate webhook on every call to save(), or only for jobs with a terminal status (e.g. completed or errored)? The former would provide the most flexibility, though I worry about people creating non-conditional webhooks that fire each time a job is created, executed, and completed.

@jeremystretch commented on GitHub (Feb 28, 2023): @kkthxbye-code would we want to evaluate webhook on _every_ call to `save()`, or only for jobs with a terminal status (e.g. completed or errored)? The former would provide the most flexibility, though I worry about people creating non-conditional webhooks that fire each time a job is created, executed, and completed.
Author
Owner

@kkthxbye-code commented on GitHub (Feb 28, 2023):

@jeremystretch - The original issue we were having, was that we had to poll to check for script completion when triggering scripts from external systems. So only triggering for terminal statuses would probably be fine for that use-case. However I don't think it should be an issue doing it on all saves, unless JobResults are saved multiple times during execution? A normal script run would be Pending -> Running -> Completed right?

@kkthxbye-code commented on GitHub (Feb 28, 2023): @jeremystretch - The original issue we were having, was that we had to poll to check for script completion when triggering scripts from external systems. So only triggering for terminal statuses would probably be fine for that use-case. However I don't think it should be an issue doing it on all saves, unless JobResults are saved multiple times during execution? A normal script run would be Pending -> Running -> Completed right?
Author
Owner

@jeremystretch commented on GitHub (Feb 28, 2023):

Right, what I mean is that each change to a job's status has to be written to the database (although it might not actually call save()), which could in theory trigger a webhook each time.

@jeremystretch commented on GitHub (Feb 28, 2023): Right, what I mean is that each change to a job's status has to be written to the database (although it might not actually call `save()`), which could in theory trigger a webhook each time.
Author
Owner

@jeremystretch commented on GitHub (Feb 28, 2023):

I suppose for the initial implementation at least we can enable webhooks for all statuses, and then constrain to only terminal statuses if needed.

@jeremystretch commented on GitHub (Feb 28, 2023): I suppose for the initial implementation at least we can enable webhooks for _all_ statuses, and then constrain to only terminal statuses if needed.
Author
Owner

@jeremystretch commented on GitHub (Feb 28, 2023):

I ended up introducing two new event types, job_start and job_end, which trigger at the beginning and end of a job's execution respectively. These map to the start() and (new) terminate() methods on the JobResult class, which handle triggering webhooks in addition to updating the job's status.

@jeremystretch commented on GitHub (Feb 28, 2023): I ended up introducing two new event types, `job_start` and `job_end`, which trigger at the beginning and end of a job's execution respectively. These map to the `start()` and (new) `terminate()` methods on the `JobResult` class, which handle triggering webhooks in addition to updating the job's status.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6258