-
-
Notifications
You must be signed in to change notification settings - Fork 258
[fix] Ignore current task when checking active tasks #1204 #1205
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
base: master
Are you sure you want to change the base?
[fix] Ignore current task when checking active tasks #1204 #1205
Conversation
…1204 The _is_update_in_progress function was incorrectly detecting the current Celery task as another running task, causing update_config to exit early. This fix excludes the current task by comparing task IDs, ensuring only other instances for the same device are considered. Fixes openwisp#1204
WalkthroughThis change fixes task self-detection in Celery deduplication logic. Sequence Diagram(s)sequenceDiagram
participant Worker as Current Worker
participant Celery as Celery Inspect
participant Other as Other Worker
Worker->>Celery: inspect.active()
Celery-->>Worker: list of active tasks (each with worker, id, name, kwargs)
Worker->>Worker: get current_task.request.id
alt Old logic (pre-change)
Worker->>Worker: if any active task matches name+device -> return True
else New logic (post-change)
Worker->>Worker: ignore active task with id == current_task.id
Worker->>Worker: if any remaining active task matches name+device -> return True
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
✏️ Tip: You can disable this entire section by setting Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…tive tasks - openwisp#1204 The _is_update_in_progress function was incorrectly detecting the current Celery task as another running task, causing update_config to exit early. This fix excludes the current task by comparing task IDs, ensuring only other instances for the same device are considered. Added tests to cover same worker (should not skip) and different worker (should skip) scenarios. Fixes openwisp#1204
…ive tasks - openwisp#1204 The _is_update_in_progress function was incorrectly detecting the current Celery task as another running task, causing update_config to exit early. This fix excludes the current task by comparing task IDs, ensuring only other instances for the same device are considered. Added tests to cover same worker (should not skip) and different worker (should skip) scenarios. Fixes openwisp#1204
nemesifier
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking this up @piyushdev04.
Are you sure the tests fail without the patch? I haven't tried yet but will try soon, please double check and ensure the failure message is clear when tests fail.
See my other comment below.
| else: | ||
| current_task_id = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| else: | |
| current_task_id = None |
Not needed
| for task in task_list: | ||
| if task["name"] == _TASK_NAME and str(device_id) in task["args"]: | ||
| return True | ||
| if task.get("id") != current_task_id: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid nesting this and add it to the previous if, we should probably rewrite this using all() https://docs.python.org/3/library/functions.html#all
…ive tasks - openwisp#1204 The _is_update_in_progress function was incorrectly detecting the current Celery task as another running task, causing update_config to exit early. This fix excludes the current task by comparing task IDs, ensuring only other instances for the same device are considered. Added tests to cover same worker (should not skip) and different worker (should skip) scenarios. Fixes openwisp#1204
…ive tasks - openwisp#1204 The _is_update_in_progress function was incorrectly detecting the current Celery task as another running task, causing update_config to exit early. This fix excludes the current task by comparing task IDs, ensuring only other instances for the same device are considered. Added tests to cover same worker (should not skip) and different worker (should skip) scenarios. Fixes openwisp#1204
|
Hi @nemesifier , I checked locally on master and TestIsUpdateInProgress.test_is_update_in_progress_same_worker does fail without the patch, and it passes with the patch applied. All other tests for this function also pass. |
pandafy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piyushdev04 can you verify that this patch work when there are multiple celery workers? (launch the celery workers with --concurrency 4 flag).
Have you tested the fix manually?
| except ObjectDoesNotExist as e: | ||
| logger.warning(f'update_config("{device_id}") failed: {e}') | ||
| return | ||
| if _is_update_in_progress(device_id): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's log at INFO level here to convey that the task was skipped because another task is in progress.
…ive tasks openwisp#1204 The _is_update_in_progress function was incorrectly detecting the current Celery task as another running task, causing update_config to exit early. This fix excludes the current task by comparing task IDs, ensuring only other instances for the same device are considered. Added tests to cover same worker (should not skip) and different worker (should skip) scenarios. Additionally, added INFO-level logging to convey when a task is skipped because another task is in progress. Fixes openwisp#1204
bf1ba35 to
3c989ae
Compare
…ive tasks openwisp#1204 The _is_update_in_progress function was incorrectly detecting the current Celery task as another running task, causing update_config to exit early. This fix excludes the current task by comparing task IDs, ensuring only other instances for the same device are considered. Added tests to cover same worker (should not skip) and different worker (should skip) scenarios. Additionally, added INFO-level logging to convey when a task is skipped because another task is in progress. Fixes openwisp#1204
The _is_update_in_progress function was incorrectly detecting the current Celery task as another running task, causing update_config to exit early. This fix excludes the current task by comparing task IDs, ensuring only other instances for the same device are considered.
Fixes #1204
Checklist
Reference to Existing Issue
Closes #1204.
Description of Changes
Updated _is_update_in_progress to ignore the currently executing Celery task by comparing task IDs.
Added tests to verify behavior for:
Verification / Tests:
openwisp_controller/connection/tests/test_tasks.py::TestIsUpdateInProgress PASSED [100%]