Update component status only when it has changed

This commit is contained in:
Jacek Szubert
2017-03-09 18:10:18 +11:00
parent ffa141d114
commit da7568300e

View File

@@ -83,6 +83,7 @@ class Configuration(object):
# We need the current status so we monitor the status changes. This is necessary for creating incidents.
self.status = get_current_status(self.api_url, self.component_id, self.headers)
self.previous_status = self.status
# Get remaining settings
self.public_incidents = int(os.environ.get('CACHET_PUBLIC_INCIDENTS') or self.data['cachet']['public_incidents'])
@@ -180,6 +181,10 @@ class Configuration(object):
"""Pushes the status of the component to the cachet server. It will update the component
status based on the previous call to evaluate().
"""
if self.previous_status == self.status:
return
self.previous_status = self.status
params = {'id': self.component_id, 'status': self.status}
component_request = requests.put('%s/components/%d' % (self.api_url, self.component_id), params=params,
headers=self.headers)