mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 11:56:18 -05:00
Fallout: say a forecast's last hour is held only when it is; check kept climatology months (#1016)
The winds follow the burst hour chosen, so an out-of-date forecast's last hour is held for the whole simulation only when it is the hour chosen; otherwise from when the chosen hour's 48 hours pass it, or not at all. The panel now says just that, and says separately that the forecast is out of date. A kept climatology month is hashed against its pinned sha256 before it is listed or served (again only once it changes); one that is not what is expected is fetched again. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d4d288f84a
commit
3ae978dc53
4 changed files with 69 additions and 16 deletions
|
|
@ -56,12 +56,31 @@ def month_name(month: int) -> str:
|
|||
return f'month-{month:02d}.bin.gz'
|
||||
|
||||
|
||||
# The kept files found to be what is expected: path -> (size, mtime) when hashed.
|
||||
_checked = dict()
|
||||
|
||||
|
||||
def month_path(month: int) -> Optional[Path]:
|
||||
"""The kept file of `month`, or None."""
|
||||
if month not in MONTHS:
|
||||
"""The kept file of `month`, or None if there is none, or it is not the file expected (it is then
|
||||
fetched again). A file is hashed again only after it changes."""
|
||||
expected = MONTHS.get(month)
|
||||
if not expected:
|
||||
return None
|
||||
path = climatology_directory() / month_name(month)
|
||||
return path if path.is_file() else None
|
||||
try:
|
||||
stat = path.stat()
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
if _checked.get(path) == (stat.st_size, stat.st_mtime_ns):
|
||||
return path
|
||||
with path.open('rb') as fh:
|
||||
actual = hashlib.file_digest(fh, 'sha256').hexdigest()
|
||||
if actual != expected:
|
||||
_checked.pop(path, None)
|
||||
logger.warning(f'{path} is not the climatology expected (sha256 {actual}); it will be fetched again')
|
||||
return None
|
||||
_checked[path] = (stat.st_size, stat.st_mtime_ns)
|
||||
return path
|
||||
|
||||
|
||||
def months_kept() -> List[int]:
|
||||
|
|
|
|||
|
|
@ -116,3 +116,21 @@ async def test_worker_waits_for_internet_and_drive(test_directory, published, fl
|
|||
flags.media_mounted.set()
|
||||
await asyncio.wait_for(worker, timeout=5)
|
||||
fetch.assert_awaited_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_month_kept_must_be_what_is_expected(test_directory, published):
|
||||
"""A kept month that is changed, or replaced, is not listed or served, and is fetched again."""
|
||||
data, bodies = published
|
||||
get, asked = fake_get(bodies)
|
||||
with mock.patch('modules.map.climatology.aiohttp_get', get), mock.patch('modules.map.climatology.asyncio.sleep'):
|
||||
await climatology.fetch_missing()
|
||||
path = climatology.month_path(1)
|
||||
assert path
|
||||
|
||||
path.write_bytes(gzip.compress(b'WFCL another month'))
|
||||
assert climatology.month_path(1) is None
|
||||
assert climatology.months_kept() == [2]
|
||||
|
||||
assert await climatology.fetch_missing() == [1]
|
||||
assert climatology.month_path(1).read_bytes() == data[1]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue