22
33from django .contrib .contenttypes .fields import GenericForeignKey
44from django .contrib .contenttypes .models import ContentType
5- from django .db import models
5+ from django .db import models , transaction
66from django .db .models .signals import post_save
7+ from django .dispatch import receiver
78from django .utils .functional import cached_property
89from django .utils .module_loading import import_string
910from django .utils .translation import gettext_lazy as _
@@ -76,15 +77,13 @@ def perform_check(self, store=True):
7677
7778
7879if app_settings .AUTO_PING :
79- from django .db import transaction
80- from django .dispatch import receiver
8180 from openwisp_monitoring .check .tasks import auto_create_ping
8281
8382 @receiver (post_save , sender = Device , dispatch_uid = 'auto_ping' )
8483 def auto_ping_receiver (sender , instance , created , ** kwargs ):
8584 """
8685 Implements OPENWISP_MONITORING_AUTO_PING
87- The creation step is executed in the backround
86+ The creation step is executed in the background
8887 """
8988 # we need to skip this otherwise this task will be executed
9089 # every time the configuration is requested via checksum
@@ -96,6 +95,28 @@ def auto_ping_receiver(sender, instance, created, **kwargs):
9695 model = sender .__name__ .lower (),
9796 app_label = sender ._meta .app_label ,
9897 object_id = str (instance .pk ),
99- created = created ,
98+ )
99+ )
100+
101+
102+ if app_settings .AUTO_CONFIG_MODIFIED :
103+ from openwisp_monitoring .check .tasks import auto_create_config_modified
104+
105+ @receiver (post_save , sender = Device , dispatch_uid = 'auto_config_modified' )
106+ def auto_config_modified_receiver (sender , instance , created , ** kwargs ):
107+ """
108+ Implements OPENWISP_MONITORING_AUTO_CONFIG_MODIFIED
109+ The creation step is executed in the background
110+ """
111+ # we need to skip this otherwise this task will be executed
112+ # every time the configuration is requested via checksum
113+ if not created :
114+ return
115+ with transaction .atomic ():
116+ transaction .on_commit (
117+ lambda : auto_create_config_modified .delay (
118+ model = sender .__name__ .lower (),
119+ app_label = sender ._meta .app_label ,
120+ object_id = str (instance .pk ),
100121 )
101122 )
0 commit comments