refactor/package-structure #2

Merged
rs merged 18 commits from refactor/package-structure into main 2026-08-31 21:38:27 +00:00
Owner
No description provided.
rs added 15 commits 2026-08-31 17:44:37 +00:00
Break waifu_of_the_day.py into a structured package with clear module
ownership: config, image_api, tagger, discord_bot, metrics, logging_setup,
and a thin main.py entrypoint.

- Introduce a typed Config dataclass with validation and externalized
  tunables (retries, sleep, filesize, tag thresholds, image APIs) loaded
  from env, replacing module-level constants and sys.exit-based checks.
- Fix file handling: images are held in io.BytesIO instead of fragile
  on-disk filename matching, and cleanup no longer depends on post success.
- Decouple config from deployment: add new tunables to the helm chart
  configmap/values and wire them through the cronjob env.
- Update Dockerfile to ship the package and new entrypoint.
- discord_bot: stop wrapping the same time_total histogram twice
  (taskrun and upload_waifu both timed the full run), keep the
  upload timing on post_on_discord only
- discord_bot: await asyncio.sleep instead of blocking time.sleep in
  the retry loop and only log/sleep when a next attempt remains
- configmap: quote all rendered values and add sane defaults so the
  chart renders even when callers omit the new keys
- argocd apps: pass the new config valuesObject entries to prod and
  test so they keep rendering against the updated chart
- metrics: drop the unused TYPE_CHECKING import
- logging_setup: cover import-untyped in the logging_loki ignore
Add an arc42-compliant architecture document for the waifu package
structure, including Mermaid diagrams (component overview, sequence,
class, deployment, and CI/CD views) that render directly in Forgejo.

Covers: introduction/goals, constraints, technical goals, stakeholders,
quality scenarios, solution strategy, module structure, runtime view,
deployment view, quality aspects, and known issues/risks.
The time_total histogram was declared but never incremented anywhere in
the codebase, so it was a dead metric. Remove it.
_upload_waifu previously swallowed the post exception and still returned
True, so a failed discord send was treated as a success and set the
last-success metric. Now a post failure returns False so the retry loop
can try again.
The discord attachment was always named waifu.png regardless of the real
image format. Detect the image type from its magic bytes (jpeg, png, gif,
webp) and name the file accordingly.
download_data and get_tags ran synchronous requests calls inside the
async pipeline, blocking the event loop. Replace them with aiohttp so the
http calls are genuinely async.
The cronjob volume used the misspelled field emptryDir instead of
emptyDir, which would render an invalid volume definition.
All configmap keys are already injected via explicit valueFrom
configMapKeyRef entries, so the additional envFrom configMapRef was
redundant. Remove it.
The tagger endpoint was hardcoded to http://tagger/, which only worked
in-cluster with the chart's ExternalName service. Move it into Config
(overridable via the TAGGER_URL env var / configmap) and thread it
through to get_tags.
The _env_bool helper was defined but never used. Remove it.
Pin the direct dependencies to concrete versions for reproducible
builds, and add aiohttp which is now used by the image api and tagger
clients.
The README pointed at build_process.sh and build_helmchart.sh, which do
not exist. Describe the actual deployment options (Dockerfile and the
helm chart) and point to config.py for the env-var reference.
The loki handler infinite-loops at DEBUG level. Instead of relying on
operators to avoid LOGLEVEL=DEBUG, clamp the level to INFO and log a
warning whenever loki is configured.
docs: update arc42 doc for resolved issues
Some checks failed
/ lint-and-check-kubernetes (pull_request) Failing after 6s
/ lint-and-check-python (pull_request) Failing after 25s
37b59d9069
Update the architecture document to reflect the fixes:
- remove the dead job_runtime_total metric from the metrics table
- add the new TAGGER_URL config option
- note aiohttp async usage in image_api and tagger
- rewrite section 11 as a resolved-issues table with a
  remaining-caveats subsection
- adjust constraints, solution strategy, and diagrams
- Reorganize to the official 12-section arc42 order (adds Context &
  Scope and Crosscutting Concepts; merges module detail into the
  building block view; separates Architecture Decisions).
- Add intent/rationale throughout: why the system exists, scope
  (in/out), why each decision, and why the decomposition is shaped
  this way.
- Rework section 5 as a proper building block view: level-1 whitebox
  (layered) + motivation + black-box table; level-2 whitebox of
  WaifuBot; level-3 zoom into the image-download sub-step.
- Split the overcrowded diagrams: the single 9-participant sequence
  becomes 3 focused runtime scenarios, and the big k8s/ArgoCD diagram
  becomes a per-namespace runtime topology plus an environments/delivery
  diagram.

Documentation only; no source changes.
Edge labels containing unquoted parentheses (e.g. 'POST image
(optional)') broke mermaid parsing. Quote those labels in the system
context and runtime topology diagrams.
Sequence message text containing unquoted parentheses
(e.g. asyncio.run(bot.run()), return False) broke mermaid parsing.
Reword the messages in all three runtime scenarios to avoid parens
and double quotes.
rs merged commit 6251354234 into main 2026-08-31 21:38:27 +00:00
rs deleted branch refactor/package-structure 2026-08-31 21:38:27 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rs/acidwaifu!2
No description provided.