Skip to content

Commit

Permalink
Be more specific about 'change time'
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtlmoon committed Jan 6, 2025
1 parent e12ba25 commit 0f28446
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions changedetectionio/update_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ def run(self):
pass

else:
fetch_start_time = time.time() # Also used a key in history.txt
uuid = queued_item_data.item.get('uuid')
self.current_uuid = uuid
if uuid in list(self.datastore.data['watching'].keys()) and self.datastore.data['watching'][uuid].get('url'):
changed_detected = False
fetch_start_time = round(time.time()) # Also used a key in history.txt
contents = b''
process_changedetection_results = True
update_obj = {}
Expand Down Expand Up @@ -286,6 +286,11 @@ def run(self):
)

update_handler.call_browser()

# In reality, the actual time of when the change was detected could be a few seconds after this
# For example it should include when the page stopped rendering if using a playwright/chrome type fetch
fetch_start_time = time.time() # Also used a key in history.txt

changed_detected, update_obj, contents = update_handler.run_changedetection(watch=watch)

# Re #342
Expand Down Expand Up @@ -538,21 +543,22 @@ def run(self):

# Small hack so that we sleep just enough to allow 1 second between history snapshots
# this is because history.txt indexes/keys snapshots by epoch seconds and we dont want dupe keys
# @also - the keys are one per second at the most (for now)
if watch.newest_history_key and int(fetch_start_time) == int(watch.newest_history_key):
logger.warning(
f"Timestamp {fetch_start_time} already exists, waiting 1 seconds so we have a unique key in history.txt")
fetch_start_time += 1
time.sleep(1)

watch.save_history_text(contents=contents,
timestamp=fetch_start_time,
timestamp=int(fetch_start_time),
snapshot_id=update_obj.get('previous_md5', 'none'))


empty_pages_are_a_change = self.datastore.data['settings']['application'].get('empty_pages_are_a_change', False)
if update_handler.fetcher.content or (not update_handler.fetcher.content and empty_pages_are_a_change):
# attribute .last_changed is then based on this data
watch.save_last_fetched_html(contents=update_handler.fetcher.content, timestamp=fetch_start_time)
watch.save_last_fetched_html(contents=update_handler.fetcher.content, timestamp=int(fetch_start_time))

# Notifications should only trigger on the second time (first time, we gather the initial snapshot)
if watch.history_n >= 2:
Expand Down Expand Up @@ -581,7 +587,7 @@ def run(self):
pass

self.datastore.update_watch(uuid=uuid, update_obj={'fetch_time': round(time.time() - fetch_start_time, 3),
'last_checked': fetch_start_time,
'last_checked': int(fetch_start_time),
'check_count': count
})

Expand Down

0 comments on commit 0f28446

Please sign in to comment.