Refactor SyncDataSourceJob to change the DataSource status to "queued" when enqueued #10648

Closed
opened 2025-12-29 21:34:10 +01:00 by adam · 3 comments
Owner

Originally created by @leomarssilva on GitHub (Jan 15, 2025).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v4.2.1

Feature type

Change to existing functionality

Triage priority

I volunteer to perform this work (if approved)

Proposed functionality

The snippet of code below, used to enqueue DataSource syncing, is duplicated in the following files: netbox/core/api/views.py and netbox/core/views.py

# Enqueue the sync job & update the DataSource's status
job = SyncDataSourceJob.enqueue(instance=datasource, user=request.user)
datasource.status = DataSourceStatusChoices.QUEUED
DataSource.objects.filter(pk=datasource.pk).update(status=datasource.status)

I propose moving the status update code to a new enqueue method on SyncDataSourceJob.

Use case

It removes duplicated code, and the logic can be reused easily for new functionalities (e.g., https://github.com/netbox-community/netbox/issues/18287) or to trigger DataSource syncing from plugins.

Database changes

None.

External dependencies

None.

Originally created by @leomarssilva on GitHub (Jan 15, 2025). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v4.2.1 ### Feature type Change to existing functionality ### Triage priority I volunteer to perform this work (if approved) ### Proposed functionality The snippet of code below, used to enqueue DataSource syncing, is duplicated in the following files: [netbox/core/api/views.py](https://github.com/netbox-community/netbox/blob/v4.2.1/netbox/core/api/views.py#L53-L56) and [netbox/core/views.py](https://github.com/netbox-community/netbox/blob/v4.2.1/netbox/core/views.py#L81-L84) ```python # Enqueue the sync job & update the DataSource's status job = SyncDataSourceJob.enqueue(instance=datasource, user=request.user) datasource.status = DataSourceStatusChoices.QUEUED DataSource.objects.filter(pk=datasource.pk).update(status=datasource.status) ``` I propose moving the status update code to a new `enqueue` method on [SyncDataSourceJob](https://github.com/netbox-community/netbox/blob/v4.2.1/netbox/core/jobs.py#L12). ### Use case It removes duplicated code, and the logic can be reused easily for new functionalities (e.g., https://github.com/netbox-community/netbox/issues/18287) or to trigger DataSource syncing from plugins. ### Database changes None. ### External dependencies None.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 21:34:10 +01:00
adam closed this issue 2025-12-29 21:34:10 +01:00
Author
Owner

@bctiemann commented on GitHub (Feb 20, 2025):

@leomarssilva This sounds worthwhile. Are you still interested in working on this and submitting a PR?

@bctiemann commented on GitHub (Feb 20, 2025): @leomarssilva This sounds worthwhile. Are you still interested in working on this and submitting a PR?
Author
Owner

@github-actions[bot] commented on GitHub (May 22, 2025):

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 (May 22, 2025): 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/main/CONTRIBUTING.md).
Author
Owner

@leomarssilva commented on GitHub (Jun 9, 2025):

Hi @bctiemann, sorry, I was working on other projects.

Later this week, I'll go back to this and open a PR :)

@leomarssilva commented on GitHub (Jun 9, 2025): Hi @bctiemann, sorry, I was working on other projects. Later this week, I'll go back to this and open a PR :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10648