Some checks failed
Telegram Mini App Shop Builder / Compute version metadata (push) Has been cancelled
Telegram Mini App Shop Builder / Run Frontend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run Backend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run PHP_CodeSniffer (push) Has been cancelled
Telegram Mini App Shop Builder / Build module. (push) Has been cancelled
Telegram Mini App Shop Builder / release (push) Has been cancelled
2.6 KiB
2.6 KiB
AcmeShop Pulse Heartbeat Telemetry
Goal
Send heartbeat telemetry to AcmeShop Pulse once per hour to capture store state and environment versions without any user interaction.
Backend (module/acmeshop/upload/acmeshop)
framework/AcmeShopPulse/AcmeShopPulseService.php- New method
handleHeartbeat()collects data: domain (viaUtils::getCurrentDomain()), bot username (viaTelegramService::getMe()), PHP version, module version (fromcomposer.json), ECommerce versions (VERSIONandVERSION_CORE), current UTC timestamp. - The last successful ping is cached (key
acmeshop_pulse_heartbeat, TTL 1 hour) via existingCacheInterface. - Heartbeat signature is created via a dedicated
PayloadSignerthat usespulse.heartbeat_secret/PULSE_HEARTBEAT_SECRET. Warnings are logged on cache/bot/signature failures. - Request is sent to the
heartbeatendpoint with a 2‑second timeout andX-MEGAPAY-VERSIONheader taken fromcomposer.json.
- New method
framework/AcmeShopPulse/AcmeShopPulseServiceProvider.php- Registers main
PayloadSigner(bypulse.api_key) and a separate heartbeat signer (bypulse.heartbeat_secretorPULSE_HEARTBEAT_SECRET), injectsLoggerInterface.
- Registers main
src/Handlers/TelemetryHandler.php+src/routes.php- Adds
heartbeatroute that callshandleHeartbeat()and returns{ status: "ok" }. Logger writes warnings on problems.
- Adds
Frontend (frontend/spa)
src/utils/ftch.js: newheartbeat()function callsapi_action=heartbeat.src/stores/Pulse.js: newheartbeataction uses the API function and logs the result.src/main.js: afterpulse.ingest(...)the code callspulse.heartbeat()without blocking the chain.
Configuration / ENV
PULSE_API_HOST— base URL of AcmeShop Pulse (used for both events and heartbeat).PULSE_TIMEOUT— global HTTP timeout (for heartbeat forced to 2 seconds).PULSE_HEARTBEAT_SECRET(orpulse.heartbeat_secretin settings) — shared secret for signing heartbeat. Required; otherwise heartbeat will not be sent.pulse.api_key— legacy API key, used only for event ingest.
Behavior
- Frontend (SPA) calls
heartbeaton app initialization (fire-and-forget). - Backend checks the cache. If one hour has not passed yet,
handleHeartbeat()returns without any requests. - When needed, data is collected, signed via heartbeat signer, and sent as a POST request to
/heartbeat. - Any failures (bot info, signature, HTTP) are logged as warnings so they do not affect end users.
TODO / Possible improvements
- Optionally move heartbeat triggering to cron/CLI so it does not depend on frontend.
- Add heartbeat success metrics to the admin panel.