Overview
rearjackman is deployed as a Cloudflare Worker with D1 database, queue bindings, and scheduled cron triggers for automatic data synchronization.Prerequisites
- Node.js installed
- Cloudflare account
- Wrangler CLI installed
Configuration
The application is configured viawrangler.toml:
Key configuration settings
- compatibility_flags:
nodejs_compatenables Node.js APIs - routes: Custom domain configuration
- crons: Scheduled trigger runs every Monday at 6:00 AM UTC
- migrations_dir: Location of D1 database migration files
D1 database setup
Create the D1 database:wrangler.toml with the database ID:
Running migrations
Apply database migrations:The
DB binding is used throughout the codebase to access the D1 database. See src/worker.ts for query examples.Queue setup
Create the sync queue:wrangler.toml includes:
- Producer binding:
SYNC_QUEUE- used to send messages to the queue - Consumer settings:
max_batch_size: 1- processes one sync job at a timemax_batch_timeout: 5- waits up to 5 seconds before processing
Queue message format
The sync queue accepts messages with this structure:The queue handler is defined in
src/worker.ts:104. It processes race data synchronization jobs asynchronously.Cron triggers
The scheduled handler runs every Monday at 6:00 AM UTC (0 6 * * MON):
- Checks the current season’s race schedule
- Identifies completed races since the last sync
- Queues a sync job for the most recent completed race
src/worker.ts:70-102.
Environment variables and secrets
Set required secrets before deployment. See Environment variables for details.Deployment
Local development
Run the worker locally with bindings:- Local D1 database
- Local queue emulation
- Hot reload on file changes
Production deployment
Deploy to Cloudflare Workers:wrangler deploy which:
- Builds the TypeScript worker code
- Uploads the worker to Cloudflare
- Activates bindings (DB, SYNC_QUEUE)
- Configures routes and triggers
Observability
The worker has observability enabled inwrangler.toml:
Custom domain
The worker is configured to use a custom domain via theroutes configuration:
Bindings reference
The worker uses these bindings (defined insrc/types.ts:3-7):
| Binding | Type | Purpose |
|---|---|---|
DB | D1Database | Access to D1 database for race data |
SYNC_SECRET | string | Secret for authenticating manual sync requests |
SYNC_QUEUE | Queue | Queue for asynchronous data sync jobs |
Next steps
- Configure environment variables
- Review wrangler.toml documentation
- Learn about D1 databases
- Explore Cloudflare Queues