File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed
openwisp_controller/connection Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change 1616_TASK_NAME = "openwisp_controller.connection.tasks.update_config"
1717
1818
19- def _is_update_in_progress (device_id ):
19+ def _is_update_in_progress (device_id , current_task_id = None ):
2020 active = current_app .control .inspect ().active ()
2121 if not active :
2222 return False
2323 # check if there's any other running task before adding it
2424 for task_list in active .values ():
2525 for task in task_list :
26- if task ["name" ] == _TASK_NAME and str (device_id ) in task ["args" ]:
26+ if (
27+ task ["name" ] == _TASK_NAME
28+ and str (device_id ) in task ["args" ]
29+ and task ["id" ] != current_task_id
30+ ):
2731 return True
2832 return False
2933
3034
31- @shared_task
32- def update_config (device_id ):
35+ @shared_task ( bind = True )
36+ def update_config (self , device_id ):
3337 """
3438 Launches the ``update_config()`` operation
3539 of a specific device in the background
@@ -48,7 +52,7 @@ def update_config(device_id):
4852 except ObjectDoesNotExist as e :
4953 logger .warning (f'update_config("{ device_id } ") failed: { e } ' )
5054 return
51- if _is_update_in_progress (device_id ):
55+ if _is_update_in_progress (device_id , current_task_id = self . request . id ):
5256 return
5357 try :
5458 device_conn = DeviceConnection .get_working_connection (device )
Original file line number Diff line number Diff line change @@ -1032,7 +1032,13 @@ def test_device_update_config_in_progress(
10321032
10331033 with mock .patch ("celery.app.control.Inspect.active" ) as mocked_active :
10341034 mocked_active .return_value = {
1035- "task" : [{"name" : _TASK_NAME , "args" : [str (conf .device .pk )]}]
1035+ "task" : [
1036+ {
1037+ "name" : _TASK_NAME ,
1038+ "args" : [str (conf .device .pk )],
1039+ "id" : "other-task-id" ,
1040+ }
1041+ ]
10361042 }
10371043 conf .config = {"general" : {"timezone" : "UTC" }}
10381044 conf .full_clean ()
@@ -1054,7 +1060,7 @@ def test_device_update_config_not_in_progress(
10541060
10551061 with mock .patch ("celery.app.control.Inspect.active" ) as mocked_active :
10561062 mocked_active .return_value = {
1057- "task" : [{"name" : _TASK_NAME , "args" : ["..." ]}]
1063+ "task" : [{"name" : _TASK_NAME , "args" : ["..." ], "id" : "other-task-id" }]
10581064 }
10591065 conf .config = {"general" : {"timezone" : "UTC" }}
10601066 conf .full_clean ()
You can’t perform that action at this time.
0 commit comments