feat: compensate failed uploads and clean stale pending attachments
- upload: delete the stored object when ready fails before COMMIT or the pending row is gone (503 instead of 500); unknown COMMIT outcome keeps it - cleaner service (python -m src.cleaner): stale pending rows older than grace (900 s, must exceed 17 s live-upload bound) under FOR UPDATE SKIP LOCKED, object before row, own S3 user with read/delete only - shared session_scope for API and cleaner; early_stop process name - partial index on pending attachments, CREATE INDEX CONCURRENTLY - s3-bootstrap: cleaner user, policy and checks; make env_setup appends missing template variables to an existing .env - failure checks: cleaner on the failure stand, id-list hook actions, five new and three updated tests; driver upload-consistency - sync upload-consistency deltas into main specs (storage-consistency) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -41,23 +41,45 @@ run_dev: upgrade start_cache start_s3
|
||||
APP__RUN_MODE=console uv run python -m src
|
||||
|
||||
# шаблоны копируются только если файла ещё нет: локальные значения
|
||||
# не затираются. В новый .env подставляются случайные пароли Postgres и
|
||||
# не затираются. В .env подставляются случайные пароли Postgres и
|
||||
# Valkey и секреты S3: в шаблоне они пустые, общего секрета стенда в git
|
||||
# нет. Печатаются только имена, значения — нет
|
||||
ENV_SECRETS = POSTGRES_PASSWORD VALKEY_PASSWORD S3_ROOT_ACCESS_KEY S3_ROOT_SECRET_KEY S3_JWT_SIGNING_KEY S3_API_ACCESS_KEY S3_API_SECRET_KEY
|
||||
# нет. В существующий .env дописываются переменные шаблона, которых в нём
|
||||
# нет (секреты — случайными, остальные — значениями шаблона), прежние
|
||||
# строки не меняются (design change upload-consistency). Печатаются
|
||||
# только имена, значения — нет
|
||||
ENV_SECRETS = POSTGRES_PASSWORD VALKEY_PASSWORD S3_ROOT_ACCESS_KEY S3_ROOT_SECRET_KEY S3_JWT_SIGNING_KEY S3_API_ACCESS_KEY S3_API_SECRET_KEY S3_CLEANER_ACCESS_KEY S3_CLEANER_SECRET_KEY
|
||||
# шаблон с подставленными секретами — в поток, не в вывод команды
|
||||
ENV_FILLED = sed \
|
||||
-e "s/^POSTGRES_PASSWORD=$$/POSTGRES_PASSWORD=$$(openssl rand -hex 16)/" \
|
||||
-e "s/^VALKEY_PASSWORD=$$/VALKEY_PASSWORD=$$(openssl rand -hex 16)/" \
|
||||
-e "s/^S3_ROOT_ACCESS_KEY=$$/S3_ROOT_ACCESS_KEY=$$(openssl rand -hex 10)/" \
|
||||
-e "s/^S3_ROOT_SECRET_KEY=$$/S3_ROOT_SECRET_KEY=$$(openssl rand -hex 20)/" \
|
||||
-e "s/^S3_JWT_SIGNING_KEY=$$/S3_JWT_SIGNING_KEY=$$(openssl rand -hex 32)/" \
|
||||
-e "s/^S3_API_ACCESS_KEY=$$/S3_API_ACCESS_KEY=$$(openssl rand -hex 10)/" \
|
||||
-e "s/^S3_API_SECRET_KEY=$$/S3_API_SECRET_KEY=$$(openssl rand -hex 20)/" \
|
||||
-e "s/^S3_CLEANER_ACCESS_KEY=$$/S3_CLEANER_ACCESS_KEY=$$(openssl rand -hex 10)/" \
|
||||
-e "s/^S3_CLEANER_SECRET_KEY=$$/S3_CLEANER_SECRET_KEY=$$(openssl rand -hex 20)/" \
|
||||
.env.example
|
||||
# строки NAME=… шаблона, имени которых в .env нет, — в конец .env под
|
||||
# комментарием; в вывод — только имена
|
||||
ENV_APPEND_MISSING = awk -F= ' \
|
||||
BEGIN { \
|
||||
while ((getline line < ".env") > 0) \
|
||||
if (line ~ /^[A-Za-z_][A-Za-z0-9_]*=/) { split(line, kv, "="); have[kv[1]] = 1 }; \
|
||||
close(".env"); \
|
||||
} \
|
||||
/^[A-Za-z_][A-Za-z0-9_]*=/ && !($$1 in have) { \
|
||||
if (!added++) printf "\n\# added by make env_setup from .env.example\n" >> ".env"; \
|
||||
print >> ".env"; names = names " " $$1 \
|
||||
} \
|
||||
END { if (added) print "added to existing .env:" names }'
|
||||
.PHONY: env_setup
|
||||
env_setup:
|
||||
@if [ ! -f .env ]; then \
|
||||
sed \
|
||||
-e "s/^POSTGRES_PASSWORD=$$/POSTGRES_PASSWORD=$$(openssl rand -hex 16)/" \
|
||||
-e "s/^VALKEY_PASSWORD=$$/VALKEY_PASSWORD=$$(openssl rand -hex 16)/" \
|
||||
-e "s/^S3_ROOT_ACCESS_KEY=$$/S3_ROOT_ACCESS_KEY=$$(openssl rand -hex 10)/" \
|
||||
-e "s/^S3_ROOT_SECRET_KEY=$$/S3_ROOT_SECRET_KEY=$$(openssl rand -hex 20)/" \
|
||||
-e "s/^S3_JWT_SIGNING_KEY=$$/S3_JWT_SIGNING_KEY=$$(openssl rand -hex 32)/" \
|
||||
-e "s/^S3_API_ACCESS_KEY=$$/S3_API_ACCESS_KEY=$$(openssl rand -hex 10)/" \
|
||||
-e "s/^S3_API_SECRET_KEY=$$/S3_API_SECRET_KEY=$$(openssl rand -hex 20)/" \
|
||||
.env.example > .env; \
|
||||
$(ENV_FILLED) > .env; \
|
||||
echo "new .env with random $(ENV_SECRETS)"; \
|
||||
else \
|
||||
$(ENV_FILLED) | $(ENV_APPEND_MISSING); \
|
||||
fi
|
||||
@test -f config.toml || cp config_example.toml config.toml
|
||||
@echo "env ready: .env, config.toml"
|
||||
|
||||
Reference in New Issue
Block a user