Skip to main content
The report-worker is the automated document compiler of the Hoox trading platform. Deployed as a scheduled cron isolate, this worker runs twice daily (at 06:00 and 18:00 UTC) to pull D1 transactional stats, construct a highly styled HTML5 portfolio report, spin up a serverless Cloudflare Browser Rendering Chrome instance to compile the page into a PDF buffer, offload the file to R2, and push a private download link to your Telegram.

⚡ 1. Declared Wrangler Configurations & Bindings

The report-worker mounts storage buckets, notification bindings, and is triggered by Cloudflare’s background cron engine:

🔑 2. Environmental Variables & Encrypted Secrets

  • CF_API_TOKEN: Your Cloudflare API Token with Account.Browser Rendering and Account.R2 write permissions.
  • INTERNAL_KEY_BINDING: Shared key used to validate calls from other V8 isolates.

🌐 3. Browser Rendering & PDF Print Pipeline

When the Cron schedule triggers, report-worker runs the following programmatic pipeline:

Step 1: Data Aggregation & HTML Compilation

The worker pings D1_SERVICE to retrieve P&L, win rate, and total daily fees, inserting the metrics into a styled HTML5 template utilizing Tailwind CSS and CSS Grid styling:

Step 2: Cloudflare Chrome Isolate Print

Pushes the HTML template to Cloudflare’s headless Chrome rendering pool via the REST API:

Step 3: R2 Storage & Expiration

  1. The API compiles the page and returns a raw PDF binary stream.
  2. The worker uploads the stream to the REPORTS_BUCKET R2 storage bucket using a unique, date-hashed key: reports/daily-pnl-2026-05-19.pdf
  3. A lifecycle rule on the R2 bucket automatically purges reports older than 30 days to maintain storage cleanliness.

Step 4: Dispatch Telegram Alert

Calls TELEGRAM_SERVICE to send the link:

If CF_API_TOKEN is not configured, the worker gracefully fails by compiling a rich text-only P&L summary and pushing it directly via Telegram instead of generating a PDF, guaranteeing continuous operations without hard crashes.

🔗 Next Steps

Last modified on June 17, 2026