[GH-ISSUE #97] Feature Request: Allow the ability to sync agent tasks #1997

Closed
opened 2026-03-14 02:00:46 +03:00 by kerem · 10 comments
Owner

Originally created by @bradhawkins85 on GitHub (Sep 9, 2020).
Original GitHub issue: https://github.com/amidaware/tacticalrmm/issues/97

Originally assigned to: @sadnub on GitHub.

When removing a task from a policy the task is not removed from the agents.
Removing a policy from a client/site does not remove the tasks from the agents.

Originally created by @bradhawkins85 on GitHub (Sep 9, 2020). Original GitHub issue: https://github.com/amidaware/tacticalrmm/issues/97 Originally assigned to: @sadnub on GitHub. When removing a task from a policy the task is not removed from the agents. Removing a policy from a client/site does not remove the tasks from the agents.
kerem 2026-03-14 02:00:46 +03:00
Author
Owner

@sadnub commented on GitHub (Sep 9, 2020):

@bradhawkins85 Thanks for bringing this up. I will need to rework the task deletion since it tries once to delete the task(s) from the agents then deletes the task from the UI. I think I can add a pending_deletion field to the task and check this once the agent checks in, so that offline agents will eventually get the tasks cleaned up. I will work on this.

<!-- gh-comment-id:689706449 --> @sadnub commented on GitHub (Sep 9, 2020): @bradhawkins85 Thanks for bringing this up. I will need to rework the task deletion since it tries once to delete the task(s) from the agents then deletes the task from the UI. I think I can add a pending_deletion field to the task and check this once the agent checks in, so that offline agents will eventually get the tasks cleaned up. I will work on this.
Author
Owner

@bradhawkins85 commented on GitHub (Sep 10, 2020):

thanks @sadnub
I was actually meaning that the tasks were not removing from the webui but it appears they just took a while.
pending_deletion would be good though if the agents are not removing the scheduled tasks due to being offline.

Is there a way we can clean up scheduled tasks as part of this fix to tidy up old tasks that did not get removed previously?

<!-- gh-comment-id:689959043 --> @bradhawkins85 commented on GitHub (Sep 10, 2020): thanks @sadnub I was actually meaning that the tasks were not removing from the webui but it appears they just took a while. pending_deletion would be good though if the agents are not removing the scheduled tasks due to being offline. Is there a way we can clean up scheduled tasks as part of this fix to tidy up old tasks that did not get removed previously?
Author
Owner

@sadnub commented on GitHub (Sep 10, 2020):

When checks and tasks are modified, a background task is fired off to perform the action, so the UI can return a response faster. If there are a large number of agents affected it could take a little bit for the affected checks and tasks to get deleted/created.

For cleaning up orphaned tasks on the agent that might get tricky. I could try and create a python script to compare the agent tasks and the UI and delete if it doesn't have a reference. I will have to test that.

I do have a fix for the orphaned tasks implemented, but I need to do more testing. Should be this evening.

<!-- gh-comment-id:690668534 --> @sadnub commented on GitHub (Sep 10, 2020): When checks and tasks are modified, a background task is fired off to perform the action, so the UI can return a response faster. If there are a large number of agents affected it could take a little bit for the affected checks and tasks to get deleted/created. For cleaning up orphaned tasks on the agent that might get tricky. I could try and create a python script to compare the agent tasks and the UI and delete if it doesn't have a reference. I will have to test that. I do have a fix for the orphaned tasks implemented, but I need to do more testing. Should be this evening.
Author
Owner

@sadnub commented on GitHub (Sep 11, 2020):

#100 Adds the reliable task edits on the agent. Still working on cleanup for existing agents

<!-- gh-comment-id:691131019 --> @sadnub commented on GitHub (Sep 11, 2020): #100 Adds the reliable task edits on the agent. Still working on cleanup for existing agents
Author
Owner

@sadnub commented on GitHub (Sep 14, 2020):

I was thinking about this more and it might be beneficial to have a sync tasks agent command. This will help if a task gets deleted from the agent on accident.

<!-- gh-comment-id:692346350 --> @sadnub commented on GitHub (Sep 14, 2020): I was thinking about this more and it might be beneficial to have a sync tasks agent command. This will help if a task gets deleted from the agent on accident.
Author
Owner

@bradhawkins85 commented on GitHub (Sep 14, 2020):

@sadnub sounds like a brilliant idea.
The task could remove all tactical rmm tasks and re-create them that would handle the clean up as well.

<!-- gh-comment-id:692375580 --> @bradhawkins85 commented on GitHub (Sep 14, 2020): @sadnub sounds like a brilliant idea. The task could remove all tactical rmm tasks and re-create them that would handle the clean up as well.
Author
Owner

@sadnub commented on GitHub (Oct 30, 2020):

@bradhawkins85 I just added a PR with adds command to remove tasks on agents that are already removed from the UI. You can run python manage.py remove_orphaned_tasks on the server and it will cycle through all agents.

<!-- gh-comment-id:719831010 --> @sadnub commented on GitHub (Oct 30, 2020): @bradhawkins85 I just added a PR with adds command to remove tasks on agents that are already removed from the UI. You can run `python manage.py remove_orphaned_tasks` on the server and it will cycle through all agents.
Author
Owner

@bradhawkins85 commented on GitHub (Oct 30, 2020):

Thank you @sadnub will give it a run once the PR is merged.

<!-- gh-comment-id:719833074 --> @bradhawkins85 commented on GitHub (Oct 30, 2020): Thank you @sadnub will give it a run once the PR is merged.
Author
Owner

@bradhawkins85 commented on GitHub (Nov 2, 2020):

@sadnub i'm getting an error when running the script:
I only have python3 not python so not sure if this is the issue.

tactical@tactical:/rmm/api/tacticalrmm$ python3 manage.py remove_orphaned_tasks
Traceback (most recent call last):
File "manage.py", line 10, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "manage.py", line 21, in
main()
File "manage.py", line 12, in main
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

<!-- gh-comment-id:720232241 --> @bradhawkins85 commented on GitHub (Nov 2, 2020): @sadnub i'm getting an error when running the script: I only have python3 not python so not sure if this is the issue. tactical@tactical:/rmm/api/tacticalrmm$ python3 manage.py remove_orphaned_tasks Traceback (most recent call last): File "manage.py", line 10, in main from django.core.management import execute_from_command_line ModuleNotFoundError: No module named 'django' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 21, in <module> main() File "manage.py", line 12, in main raise ImportError( ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
Author
Owner

@wh1te909 commented on GitHub (Nov 2, 2020):

you have to activate the python virtual environment first

cd /rmm/api/tacticalrmm/
source ../env/bin/activate
python manage.py remove_orphaned_tasks
<!-- gh-comment-id:720240371 --> @wh1te909 commented on GitHub (Nov 2, 2020): you have to activate the python virtual environment first ``` cd /rmm/api/tacticalrmm/ source ../env/bin/activate python manage.py remove_orphaned_tasks ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tacticalrmm#1997
No description provided.