mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-20 01:33:22 +00:00
Use secrete key to make IMAP polling offset stable
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
from hashlib import sha256
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
@@ -178,7 +178,8 @@ def parse_beat_schedule() -> dict:
|
||||
and task["env_key"] not in os.environ
|
||||
):
|
||||
# Spread default polling across the ten-minute interval.
|
||||
offset = random.randrange(10)
|
||||
secret = os.environ["PAPERLESS_SECRET_KEY"].encode()
|
||||
offset = int.from_bytes(sha256(secret).digest()) % 10
|
||||
minutes = ",".join(str(minute) for minute in range(offset, 60, 10))
|
||||
value = f"{minutes} * * * *"
|
||||
# I find https://crontab.guru/ super helpful
|
||||
|
||||
@@ -168,7 +168,7 @@ class TestParseHostingSettings:
|
||||
def make_expected_schedule(
|
||||
overrides: dict[str, dict[str, Any]] | None = None,
|
||||
disabled: set[str] | None = None,
|
||||
email_minute: str = "3,13,23,33,43,53",
|
||||
email_minute: str = "6,16,26,36,46,56",
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
Build the expected schedule with optional overrides and disabled tasks.
|
||||
@@ -310,8 +310,11 @@ class TestParseBeatSchedule:
|
||||
expected: dict[str, Any],
|
||||
mocker: MockerFixture,
|
||||
) -> None:
|
||||
mocker.patch.dict(os.environ, env, clear=False)
|
||||
mocker.patch("paperless.settings.custom.random.randrange", return_value=3)
|
||||
mocker.patch.dict(
|
||||
os.environ,
|
||||
{"PAPERLESS_SECRET_KEY": "test-secret", **env},
|
||||
clear=False,
|
||||
)
|
||||
schedule = parse_beat_schedule()
|
||||
assert schedule == expected
|
||||
|
||||
|
||||
Reference in New Issue
Block a user