Files
store-scraper-bot/plans/260426-2327-cloudflare-deploy-and-smoke/plan.md
T
tiennm99 bff1d324f5 feat: Cloudflare Workers code port (deploy pending)
Refactors source to be Worker-shaped. No live deploy yet — sister deploy plan
runs Atlas provisioning + smoke later.

- wrangler.toml with nodejs_compat_v2, daily UTC 0 cron (= 7am Asia/Ho_Chi_Minh)
- package.json: drop node-telegram-bot-api, node-cron, dotenv, pino,
  pino-pretty; add wrangler devDep; bump to 0.2.0
- src/bot/telegram-api.js: raw fetch wrapper for Telegram Bot API
- src/bot/dispatch.js: per-message dispatcher extracted from polling loop
- src/repository/mongodb.js: memoized MongoClient per warm isolate, typed
  MongoUnavailable error, fast-fail timeouts
- src/repository/store.js: factory binding env once
- All 4 repositories converted to factory shape
- src/api/{apple,google}-scraper.js: take store instead of importing repos
- src/index.js: Worker entry exporting { fetch, scheduled }; webhook validates
  X-Telegram-Bot-Api-Secret-Token; ack-then-waitUntil pattern
- src/scheduler/scheduler.js: trimmed; runDailyCheck only (no node-cron)
- src/config.js, src/logger.js: env-driven, console.log JSON output
- scripts/register-webhook.js: setWebhook + setMyCommands; --dry-run supported
- scripts/check-secret-leaks.js: lint blocks console.log(env.<SECRET>)
- plans/260426-2015-cloudflare-worker-code-port: this code port plan
- plans/260426-2327-cloudflare-deploy-and-smoke: sister deploy plan

Validated via node --check on all 32 source files; lint clean. Real deploy
gates (bundle size, cold-start CPU) run in deploy plan.
2026-04-26 23:36:39 +07:00

3.2 KiB

title, description, status, priority, effort, branch, tags, created, blockedBy, blocks
title description status priority effort branch tags created blockedBy blocks
Cloudflare Workers deploy + smoke + docs Operator-driven phases: provision Atlas, set CF secrets, run hard gates, deploy, register webhook, smoke-test all 13 commands, write docs. Sister to the code-port plan. pending P1 4h main
cloudflare-workers
deploy
smoke
atlas
2026-04-26
260426-2015-cloudflare-worker-code-port

Plan B — Deploy + Smoke

Run only after the code-port plan is complete and committed. This plan touches real accounts: Atlas (free M0) and Cloudflare (free Workers).

Reference Implementation

miti99bot Phase 01 atlas-setup — proven Atlas + nodejs_compat_v2 procedure. Lift the operator steps wholesale.

Hard Gates (can abort the plan → pivot to Upstash Redis)

Gate Phase Threshold On fail
Bundle size 02 wrangler deploy --dry-run ≤ 2.7 MiB (10% headroom under 3 MiB Free cap) Pivot to Upstash (out-of-scope here; plan + execute separately)
Cold-start CPU 02 /__mongo-ping cold cycles < 40ms CPU Escalate to Workers Paid ($5/mo) OR pivot to Upstash
Auto-pause behavior 02 Paused M0 yields catchable error within 5s Document catch path requirement; not abort-worthy

Phases

# Phase Status Effort
01 Atlas M0 + CF secrets pending 1h
02 First deploy + bundle/CPU gates pending 1h
03 Register webhook pending 0.5h
04 End-to-end smoke + docs pending 1.5h

Critical dependencies

  • 01 → 02 (deploy needs MONGODB_URI + secrets)
  • 02 → 03 (register needs live worker URL + passing gates)
  • 03 → 04 (smoke needs registered webhook)

Prerequisites (operator must have)

  • MongoDB Atlas account (free, no credit card).
  • Cloudflare account (free, no credit card).
  • wrangler login completed locally.
  • Telegram bot token (existing — same as Node deployment).

Out of scope (explicit)

  • Application code changes — handled by code plan; this plan deploys what's already on main.
  • Custom domain — *.workers.dev URL is fine for Telegram webhooks.
  • Tests — original project has none; not adding here.
  • Upstash pivot — only triggered if hard gates trip; planned then, not now.

Rollback path

  • After Phase 02 (deploy live but not registered): wrangler delete removes Worker; no public surface.
  • After Phase 03 (webhook registered): setWebhook with empty URL clears it; or rotate TELEGRAM_WEBHOOK_SECRET so future POSTs 401.
  • After Phase 04 (production live): git revert to pre-Workers commit, redeploy via Docker compose for the existing Node polling path.

Questions to confirm before Phase 01

  1. Atlas account: do you have one, or first-time setup?
  2. CF account: free Workers plan attached?
  3. Bot username for setMyCommands: same as in .env.example?
  4. Greenfield Mongo data, or existing data to import? (If existing, schedule a separate import phase.)