diff --git a/CLAUDE.md b/CLAUDE.md index 0b7fab7..be29f68 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -19,7 +19,7 @@ Limba proiectului este **romana**: cod, comentarii, commit-uri, documentatie. Fa pip3 install -r requirements.txt # Python 3.12+ # Rulare locala (dev): API + worker sunt PROCESE SEPARATE -uvicorn app.main:app --reload --port 8000 # API: dashboard /, Swagger /docs, /healthz, /metrics +uvicorn app.main:app --reload --port 8010 # API: dashboard /, Swagger /docs, /healthz, /metrics python3 -m app.worker # worker (necesar doar pentru a procesa coada) # Wrapper-ul start.sh ambaleaza mediu (test/prod) + rol (api/worker/both/finalizate) diff --git a/README.md b/README.md index 948016a..0fa0585 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,9 @@ credentialele de test (fisierul **nu** se comite). ### 1. Porneste API-ul ```bash -uvicorn app.main:app --reload --port 8000 +uvicorn app.main:app --reload --port 8010 # sau, daca uvicorn nu e pe PATH: -python3 -m uvicorn app.main:app --reload --port 8000 +python3 -m uvicorn app.main:app --reload --port 8010 ``` La prima pornire se creeaza schema SQLite si se face seed la nomenclatorul RAR (18 coduri @@ -75,10 +75,10 @@ python3 -m app.worker `start.sh` ambaleaza pornirea pe mediu (`test` / `prod`) si rol (`api` / `worker` / `both`): ```bash -./start.sh test api # API pe :8000, mediu test +./start.sh test api # API pe :8010, mediu test ./start.sh test worker --send # worker care TRIMITE la RAR test ./start.sh test both --send # API + worker impreuna (dev end-to-end, loguri in .run/) -./start.sh prod api --port 8000 # API mediu prod +./start.sh prod api --port 8010 # API mediu prod ./start.sh prod worker --send # worker prod (NU foloseste creds de test) ./start.sh status # stare procese + /healthz ./start.sh stop # opreste procesele pornite cu "both" @@ -110,10 +110,10 @@ Cu API-ul pornit, deschide in browser: | URL | Ce vezi | |-----|---------| -| `http://localhost:8000/` | **Dashboard** — stare coada, banner prezentari blocate, stare worker / ultim login RAR, editor mapari operatii, browser nomenclator, sectiune **import fisier** | -| `http://localhost:8000/docs` | **Swagger UI** — API v1 interactiv (incearca endpointurile direct din browser) | -| `http://localhost:8000/healthz` | JSON sanatate: worker viu, ultim login RAR, adancime coada | -| `http://localhost:8000/metrics` | metrici text (submissions pe status) | +| `http://localhost:8010/` | **Dashboard** — stare coada, banner prezentari blocate, stare worker / ultim login RAR, editor mapari operatii, browser nomenclator, sectiune **import fisier** | +| `http://localhost:8010/docs` | **Swagger UI** — API v1 interactiv (incearca endpointurile direct din browser) | +| `http://localhost:8010/healthz` | JSON sanatate: worker viu, ultim login RAR, adancime coada | +| `http://localhost:8010/metrics` | metrici text (submissions pe status) | ### Fluxul de import fisier (xlsx / csv) din browser @@ -179,9 +179,9 @@ end-to-end pe contul de test RAR: 4. **Vizualizeaza prezentarile trimise** — trei feluri: - - **Dashboard** (`http://localhost:8000/`) — tabelul de jos arata fiecare submission cu + - **Dashboard** (`http://localhost:8010/`) — tabelul de jos arata fiecare submission cu status (`sent`/`error`/...), `id_prezentare`, cod RAR si eroare. Se actualizeaza singur. - - **API**: `curl -s http://localhost:8000/v1/prezentari` — coada locala cu statusuri. + - **API**: `curl -s http://localhost:8010/v1/prezentari` — coada locala cu statusuri. - **Direct de la RAR** (confirmare independenta ca au ajuns): ```bash @@ -285,7 +285,7 @@ Ca worker-ul sa poata trimite pentru un service fara ca fiecare cerere sa-i poar RAR, seteaza credentialele RAR durabile pe cont (criptate Fernet at-rest): ```bash -curl -s -X POST http://localhost:8000/v1/conturi/rar-creds \ +curl -s -X POST http://localhost:8010/v1/conturi/rar-creds \ -H 'X-API-Key: rfak_...' -H 'Content-Type: application/json' \ -d '{"email": "service@exemplu.ro", "password": "parola-rar"}' ``` @@ -298,16 +298,16 @@ obligatorie. ```bash # Sanatate (neprotejat) -curl -s http://localhost:8000/healthz | python3 -m json.tool +curl -s http://localhost:8010/healthz | python3 -m json.tool # Nomenclator RAR (cache local) -curl -s http://localhost:8000/v1/nomenclator +curl -s http://localhost:8010/v1/nomenclator # Coada de prezentari (monitorizare; momentan globala + neprotejata, vezi nota de mai sus) -curl -s http://localhost:8000/v1/prezentari +curl -s http://localhost:8010/v1/prezentari # Trimite o prezentare -- dev (fara cheie API -> cont id=1) -curl -s -X POST http://localhost:8000/v1/prezentari \ +curl -s -X POST http://localhost:8010/v1/prezentari \ -H 'Content-Type: application/json' \ -d '{ "rar_credentials": {"email": "test@example.ro", "password": "secret"}, @@ -321,7 +321,7 @@ curl -s -X POST http://localhost:8000/v1/prezentari \ }' # Trimite o prezentare -- service cu cheie API (account_id curge din cheie) -curl -s -X POST http://localhost:8000/v1/prezentari \ +curl -s -X POST http://localhost:8010/v1/prezentari \ -H 'X-API-Key: rfak_...' -H 'Content-Type: application/json' \ -d '{ "rar_credentials": {"email": "service@exemplu.ro", "password": "parola-rar"}, @@ -335,7 +335,7 @@ curl -s -X POST http://localhost:8000/v1/prezentari \ }' # Import fisier prin API pentru un service (multi-tenant: contul vine din cheie) -curl -s -X POST http://localhost:8000/v1/import \ +curl -s -X POST http://localhost:8010/v1/import \ -H 'X-API-Key: rfak_...' -F 'file=@sample_import.xlsx' ``` @@ -344,16 +344,16 @@ pune cheia prin butonul "Authorize" sau adauga header-ul `X-API-Key`. ```bash # Sanatate -curl -s http://localhost:8000/healthz | python3 -m json.tool +curl -s http://localhost:8010/healthz | python3 -m json.tool # Nomenclator RAR (cache local) -curl -s http://localhost:8000/v1/nomenclator +curl -s http://localhost:8010/v1/nomenclator # Coada de prezentari -curl -s http://localhost:8000/v1/prezentari +curl -s http://localhost:8010/v1/prezentari # Trimite o prezentare (dev: fara cheie API -> cont id=1) -curl -s -X POST http://localhost:8000/v1/prezentari \ +curl -s -X POST http://localhost:8010/v1/prezentari \ -H 'Content-Type: application/json' \ -d '{ "rar_credentials": {"email": "test@example.ro", "password": "secret"}, @@ -389,7 +389,7 @@ cp .env.example .env docker compose up --build ``` -`docker-compose.yml` porneste trei containere: `api` (port 8000), `worker` si `autoheal` +`docker-compose.yml` porneste trei containere: `api` (port 8010), `worker` si `autoheal` (restarteaza worker-ul cand heartbeat-ul devine invechit). Ambele servicii folosesc acelasi image si acelasi volum SQLite persistent. diff --git a/docker-compose.yml b/docker-compose.yml index 4ab5ba5..55a5cb4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,9 +8,9 @@ services: api: build: . - command: uvicorn app.main:app --host 0.0.0.0 --port 8000 + command: uvicorn app.main:app --host 0.0.0.0 --port 8010 ports: - - "8000:8000" + - "8010:8010" volumes: - autopass-data:/data environment: @@ -20,7 +20,7 @@ services: AUTOPASS_REQUIRE_API_KEY: ${AUTOPASS_REQUIRE_API_KEY:-false} restart: always healthcheck: - test: ["CMD", "python", "-c", "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://localhost:8000/healthz').status==200 else 1)"] + test: ["CMD", "python", "-c", "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://localhost:8010/healthz').status==200 else 1)"] interval: 30s timeout: 5s retries: 3 diff --git a/start.sh b/start.sh index 78ebec9..57bc0c4 100755 --- a/start.sh +++ b/start.sh @@ -2,10 +2,10 @@ # start.sh — pornire gateway RAR AUTOPASS (api / worker) pe mediu test sau prod. # # Exemple: -# ./start.sh test api # API pe :8000, mediu test +# ./start.sh test api # API pe :8010, mediu test # ./start.sh test worker --send # worker care TRIMITE la RAR test (creds din settings.xml) # ./start.sh test both --send # API + worker impreuna (dev end-to-end) -# ./start.sh prod api --port 8000 # API mediu prod +# ./start.sh prod api --port 8010 # API mediu prod # ./start.sh prod worker --send # worker prod (NU foloseste creds de test) # ./start.sh status # stare procese + /healthz # ./start.sh stop # opreste procesele pornite cu "both" @@ -18,7 +18,7 @@ set -euo pipefail cd "$(dirname "$0")" # --- valori implicite --- -PORT=8000 +PORT=8010 HOST=0.0.0.0 RELOAD=0 SEND=0