Skip to content

Commit

Permalink
Give exact timestamp of the next re-scan in watcher mode
Browse files Browse the repository at this point in the history
  • Loading branch information
trickerer01 committed Oct 22, 2024
1 parent 88705b1 commit d83076e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async def _state_reporter(self) -> None:
downloading_last = self._download_queue_size_last
write_last = self._write_queue_size_last
elapsed_seconds = get_elapsed_time_i()
force_check = elapsed_seconds >= force_check_seconds and elapsed_seconds - last_check_seconds >= force_check_seconds
force_check = elapsed_seconds - last_check_seconds >= force_check_seconds and not self.waiting_for_watcher()
if queue_last != queue_size or downloading_last != download_count or write_last != write_count or force_check:
scan_msg = f'scanned: {f"{min(scan_count, self._orig_count)}+{extra_count:d}" if Config.lookahead else str(scan_count)}'
prescan_msg = f' (prescanned: {self._scn.get_prescanned_count():d})' if self._scn else ''
Expand Down Expand Up @@ -273,6 +273,9 @@ def can_fetch_next(self) -> bool:
def get_workload_size(self) -> int:
return len(self._seq) + self._queue.qsize() + len(self._downloads_active)

def waiting_for_watcher(self) -> bool:
return self._scn and self._scn.watcher_wait_active()

async def _try_fetch_next(self) -> VideoInfo | None:
if self._seq:
vi = self._seq[0]
Expand Down
6 changes: 5 additions & 1 deletion src/dscanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from input import wait_for_key
from logger import Log
from path_util import file_already_exists_arr
from util import get_local_time_s

__all__ = ('VideoScanWorker',)

Expand Down Expand Up @@ -107,7 +108,7 @@ async def _extend_with_extra(self) -> int:
else:
rescan_delay = min(LOOKAHEAD_WATCH_RESCAN_DELAY_MAX, max(lookahead_abs * 18, LOOKAHEAD_WATCH_RESCAN_DELAY_MIN))
Log.warn(f'[watcher] extending queue after {last_id:d} with {extra_cur:d} extra ids: {minid:d}-{maxid:d}'
f' (waiting {rescan_delay:d} seconds before rescan)')
f' (waiting {rescan_delay:d} seconds, next re-scan at [{get_local_time_s(offset=rescan_delay)}])')
return rescan_delay
return 0

Expand Down Expand Up @@ -172,6 +173,9 @@ async def run(self) -> None:
def done(self) -> bool:
return self.get_workload_size() == 0

def watcher_wait_active(self) -> bool:
return self._sleep_waiter is not None

def get_done_count(self) -> int:
return self._scan_count

Expand Down
13 changes: 12 additions & 1 deletion src/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#

import sys
from collections.abc import Iterable
from datetime import datetime
from typing import Iterable
from time import localtime

from config import Config
from defs import START_TIME, SLASH, DOWNLOAD_MODE_FULL, DEFAULT_EXT
Expand Down Expand Up @@ -44,6 +45,16 @@ def get_elapsed_time_s() -> str:
return format_time(get_elapsed_time_i())


def get_local_time_i() -> int:
"""Returns **local** time since epoch in **seconds**"""
return int(datetime.now().timestamp()) + localtime().tm_gmtoff


def get_local_time_s(*, offset=0) -> str:
"""Returns **local** time **[+offset]** in 24hr format: **hh:mm:ss**"""
return format_time((get_local_time_i() + offset) % 86400)


def normalize_path(basepath: str, append_slash=True) -> str:
"""Converts path string to universal slash-concatenated string, enclosing slash is optional"""
normalized_path = basepath.replace('\\', SLASH)
Expand Down
2 changes: 1 addition & 1 deletion src/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
APP_NAME = 'NM'
APP_VER_MAJOR = '1'
APP_VER_SUB = '8'
APP_REVISION = '476'
APP_REVISION = '477'
APP_VERSION = f'{APP_VER_MAJOR}.{APP_VER_SUB}.{APP_REVISION}'

#
Expand Down

0 comments on commit d83076e

Please sign in to comment.