-
-
Notifications
You must be signed in to change notification settings - Fork 283
[fix] Fixed update_config duplicate task detection #1204 #1292
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,20 +16,25 @@ | |
| _TASK_NAME = "openwisp_controller.connection.tasks.update_config" | ||
|
|
||
|
|
||
| def _is_update_in_progress(device_id): | ||
| def _is_update_in_progress(device_id, current_task_id=None): | ||
| active = current_app.control.inspect().active() | ||
| if not active: | ||
| return False | ||
| # check if there's any other running task before adding it | ||
| # exclude the current task by comparing task IDs | ||
| for task_list in active.values(): | ||
| for task in task_list: | ||
| if task["name"] == _TASK_NAME and str(device_id) in task["args"]: | ||
| if ( | ||
| task["name"] == _TASK_NAME | ||
| and str(device_id) in task["args"] | ||
| and task["id"] != current_task_id | ||
| ): | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| @shared_task | ||
| def update_config(device_id): | ||
| @shared_task(bind=True) | ||
| def update_config(self, device_id): | ||
| """ | ||
| Launches the ``update_config()`` operation | ||
| of a specific device in the background | ||
|
|
@@ -48,7 +53,7 @@ def update_config(device_id): | |
| except ObjectDoesNotExist as e: | ||
| logger.warning(f'update_config("{device_id}") failed: {e}') | ||
| return | ||
| if _is_update_in_progress(device_id): | ||
| if _is_update_in_progress(device_id, current_task_id=self.request.id): | ||
| return | ||
|
Comment on lines
+56
to
57
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Add an info log before skipping duplicate updates. Line 57 returns silently when another update is in progress. Add an info-level log so this background action is observable during incident/debug analysis. Suggested patch- if _is_update_in_progress(device_id, current_task_id=self.request.id):
+ if _is_update_in_progress(device_id, current_task_id=self.request.id):
+ logger.info(
+ f'Skipping update_config("{device_id}") because another update task is already running'
+ )
returnAs per coding guidelines "New code must handle errors properly ... log important background actions with info level". 🤖 Prompt for AI Agents |
||
| try: | ||
| device_conn = DeviceConnection.get_working_connection(device) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.