fix: close ghost rooms/users on startup and repair cron env#176
Merged
Conversation
- Add 'close_active_sessions' management command that logically deletes
any AnimeRoom / AnimeUser still marked alive. WebSocket session state
lives only in the Django process, so a container restart used to leave
ghost sessions counted by the public /api/.../alive endpoints forever.
- entrypoint.sh now runs the command before starting runserver/gunicorn.
- Fix the cron job that drives 'manage.py cleanup':
- Use the venv python absolute path (cron's PATH lacked /opt/venv/bin
so the job was failing every minute with 'python: not found').
- Snapshot container env to /etc/cron.d/d-party-env.sh and source it
from the job, so settings.py can read DEBUG and other compose-only
env vars that cron does not inherit.
| 冪等な操作なので、起動毎に無条件で実行してよい。 | ||
| """ | ||
|
|
||
| from django.core.management.base import BaseCommand |
Contributor
There was a problem hiding this comment.
🚫 [mypy] reported by reviewdog 🐶
Cannot find implementation or library stub for module named "django.core.management.base" [import-not-found]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
Django コンテナを作り直すと、その時接続中だった
AnimeUser/AnimeRoomがaliveのまま残り、統計 API(/api/.../alive)に幽霊セッションとして計上され続ける問題を修正する。合わせて、コンテナ内の
cronで動いているはずの retention cleanup ジョブが起動以降 1 度も成功していなかった問題も修正する。変更
streamer/management/commands/close_active_sessions.pyを追加し、AnimeUser/AnimeRoomのaliveを一括で論理削除する(冪等)。entrypoint.shが runserver/gunicorn を起動する直前に呼ぶ。/opt/venv/binが無くpython: not foundで毎分失敗していたため、venv の絶対パス/opt/venv/bin/pythonを使うようにした。settings.pyのos.environ["DEBUG"]でKeyErrorになっていた。コンテナ起動時の env を/etc/cron.d/d-party-env.shにスナップショットし、ジョブからsourceして解決。動作確認
ローカル (
docker compose) で再起動して確認: