From 3de192636bb7f170bb750f702a9a20e6dd0a6e2f Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Mon, 12 Jan 2026 10:05:42 +0100 Subject: [PATCH] feat: update GetAnnunciFromMiogest with improved error handling and validation; add curl installation in Dockerfile; implement checkAnnunci procedure for active announcements notification --- apps/backend/miogest_handler.go | 20 ++++++++---- apps/infoalloggi/Dockerfile | 1 + .../src/server/api/routers/annunci.ts | 31 +++++++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/apps/backend/miogest_handler.go b/apps/backend/miogest_handler.go index bb36eb8..bb39084 100644 --- a/apps/backend/miogest_handler.go +++ b/apps/backend/miogest_handler.go @@ -47,21 +47,29 @@ func (m *MiogestHandler) GetAnnunci() typesdefs.AnnunciXML { func (m *MiogestHandler) GetAnnunciFromMiogest() { maxRetries := 3 - baseDelay := 30 * time.Second + baseDelay := 10 * time.Second - for attempt := 0; attempt < maxRetries; attempt++ { + for attempt := range maxRetries { var err error m.AnnunciXML, err = utils.GetDataXML[typesdefs.AnnunciXML]("http://partner.miogest.com/agenzie/infoalloggi.xml") if err == nil { - // Success - m.annunci_cache_expires = time.Now().Add(1 * time.Hour) - return + // Success - validate we got data + if len(m.AnnunciXML.Annuncio) > 0 { + m.annunci_cache_expires = time.Now().Add(1 * time.Hour) + return + } + log.Printf("Warning: Successfully fetched XML but got 0 annunci") + } + + // Log the specific error type + if err != nil { + log.Printf("Failed to get annunci (attempt %d/%d): %v", attempt+1, maxRetries, err) } // Failed - check if we should retry if attempt < maxRetries-1 { - delay := baseDelay * time.Duration(1< { + const hasAnnunci = await db + .selectFrom("annunci") + .select("id") + .where("stato", "=", "Attivo") + .where("web", "is", true) + .execute(); + if (hasAnnunci.length === 0) { + await NewMail({ + template: { + mailType: "generic", + props: { + title: "Attenzione: Nessun annuncio attivo!", + testo: + "Nel sistema non รจ presente nessun annuncio con stato Attivo e visibile sul web.", + }, + }, + mail: { + subject: "Attenzione: Nessun annuncio attivo!", + to: "m.pedone98@gmail.com", + }, + }); + + return { status: "no_annunci", timestamp: Date.now() }; + } + return { status: "ok", timestamp: Date.now() }; + }), });