Skip to content

Commit

Permalink
Rebase onto master.
Browse files Browse the repository at this point in the history
  • Loading branch information
libklein committed Aug 1, 2024
1 parent 582cc3e commit b72f7be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
1 change: 1 addition & 0 deletions changedetectionio/model/App.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class model(dict):
'notification_format': default_notification_format,
'notification_title': default_notification_title,
'notification_urls': [], # Apprise URL list
'notification_notify_on_failure': False,
'pager_size': 50,
'password': False,
'render_anchor_tag_content': False,
Expand Down
41 changes: 10 additions & 31 deletions changedetectionio/update_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
import threading
import time

from changedetectionio import content_fetcher, html_tools
from .processors.restock_diff import UnableToExtractRestockData
from .processors.text_json_diff import FilterNotFoundInResponse


# A single update worker
#
# Requests for checking on a single site(watch) from a queue of watches
Expand Down Expand Up @@ -257,7 +252,7 @@ def cleanup_error_artifacts(self, uuid):
if os.path.isfile(full_path):
os.unlink(full_path)

def _update_watch(self, uuid, update_obj, exception):
def _update_watch(self, uuid, update_obj, exception, skip_notification = False):
# TODO check if update succeeded or had an error.
# If it had an error, handle notifications
# If it did not have one, clean up any error states
Expand All @@ -266,7 +261,7 @@ def _update_watch(self, uuid, update_obj, exception):
last_error = update_obj.get('last_error', False)
if last_error:
# TODO Future - message notification handlers
if self.datastore.data['watching'][uuid].get('notification_notify_on_failure', False):
if self.datastore.data['watching'][uuid].get('notification_notify_on_failure', False) and not skip_notification:
self.send_failure_notification(watch_uuid=uuid, error_text=update_obj['last_error'])
pass
else:
Expand All @@ -275,26 +270,6 @@ def _update_watch(self, uuid, update_obj, exception):

self.datastore.update_watch(uuid=uuid, update_obj=update_obj)

if isinstance(exception, FilterNotFoundInResponse) or isinstance(exception, content_fetcher.BrowserStepsStepTimout):
# Only when enabled, send the notification
if self.datastore.data['watching'][uuid].get('filter_failure_notification_send', False):
c = self.datastore.data['watching'][uuid].get('consecutive_filter_failures', 5)
c += 1
# Send notification if we reached the threshold?
threshold = self.datastore.data['settings']['application'].get(
'filter_failure_notification_threshold_attempts',
0)
print("Filter for {} not found, consecutive_filter_failures: {}".format(uuid, c))
if threshold > 0 and c >= threshold:
if not self.datastore.data['watching'][uuid].get('notification_muted'):
if isinstance(exception, FilterNotFoundInResponse):
self.send_filter_failure_notification(uuid)
else:
self.send_step_failure_notification(watch_uuid=uuid, step_n=exception.step_n)
c = 0

self.datastore.update_watch(uuid=uuid, update_obj={'consecutive_filter_failures': c})

def run(self):
now = time.time()

Expand Down Expand Up @@ -422,7 +397,8 @@ def run(self):
continue

err_text = "Warning, no filters were found, no change detection ran - Did the page change layout? update your Visual Filter if necessary."
self._update_watch(uuid=uuid, update_obj={'last_error': err_text}, exception=None)
# Do not trigger a notification - this is handled by the step failure notification
self._update_watch(uuid=uuid, update_obj={'last_error': err_text}, exception=e, skip_notification=True)

# Filter wasnt found, but we should still update the visual selector so that they can have a chance to set it up again
if e.screenshot:
Expand All @@ -444,7 +420,8 @@ def run(self):
self.send_filter_failure_notification(uuid)
c = 0

self._update_watch(uuid=uuid, update_obj={'consecutive_filter_failures': c}, exception=None)
# Do not trigger a notification - this is handled by the step failure notification
self._update_watch(uuid=uuid, update_obj={'consecutive_filter_failures': c}, exception=e, skip_notification=True)

process_changedetection_results = False

Expand Down Expand Up @@ -484,11 +461,12 @@ def run(self):

logger.debug(f"BrowserSteps exception at step {error_step} {str(e.original_e)}")

# Do not trigger a notification - this is handled by the step failure notification
self._update_watch(uuid=uuid,
update_obj={'last_error': err_text,
'browser_steps_last_error_step': error_step
}
, exception=None)
, exception=e, skip_notification=True)

if watch.get('filter_failure_notification_send', False):
c = watch.get('consecutive_filter_failures', 5)
Expand All @@ -502,7 +480,8 @@ def run(self):
self.send_step_failure_notification(watch_uuid=uuid, step_n=e.step_n)
c = 0

self._update_watch(uuid=uuid, update_obj={'consecutive_filter_failures': c}, exception=None)
# Do not trigger a notification - this is handled by the step failure notification
self._update_watch(uuid=uuid, update_obj={'consecutive_filter_failures': c}, skip_notification=True)

process_changedetection_results = False

Expand Down

0 comments on commit b72f7be

Please sign in to comment.