Member-only story
Headline Optimizations: Data Fetching and Storing with Cloudflare
Ever wondered how data fetching and storing works using Cloudflare’s infrastructure? In my current side project, I'm all about providing Conversion Rate Optimization (CRO) services. Basically, I generate headline variations based on high-performing ones that are similar to the headline you provided, aiming to optimize content for better performance. This article covers the scheduled job of fetching the data, while another article will cover the RAG support.
Let’s dive into how I make this happen!
Scheduled Job
First up, we’ve got a scheduled job that fetches the latest reporting data at regular intervals. It’s defined in the src/index.ts
file.
// src/index.ts
export default {
// ... // Scheduled event handler for daily reporting
async scheduled(controller: ScheduledController, env: Env, ctx: ExecutionContext): Promise<void> {
// Fetch reporting data for previous day
await fetchDailyReportingData(env);
}, // ...
};
This scheduled
function runs based on the cron configuration specified in wrangler.toml
.
# wrangler.toml
[triggers]
crons = ["0 0 * * *"] # Run daily at midnight UTC