This document explains how to set up the HackerNews cron job on Val.Town.
The hackernews-cron.ts file contains a cron job that:
hackernews-cron.ts into the ValThe cron job directly imports and uses your existing video generation logic, so it requires the same environment variables as your main application:
Required:
GEMINI_API_KEY - Your Google Gemini API key (required for video generation)Optional:
ADMIN_PASSWORD - Your admin password (if you want to use the admin interface)Note: No additional environment variables are needed! The cron job directly calls the generateVideoAsync function instead of making HTTP requests, making it simpler and more efficient.
In Val.Town:
0 * * * * (cron syntax)You can easily adjust the number of stories to process by editing the constant at the top of the file:
const TOP_STORIES_LIMIT = 10; // Change this to process more or fewer stories
Common values:
10 - Top 10 stories (default, recommended for cost control)20 - Top 20 stories50 - Top 50 stories100 - Top 100 storiesgenerateVideoAsync() function with the default promptThe cron job uses the getVideoByUrl() database query to check if a URL has already been processed. This ensures:
Note: If you want to regenerate a video for a URL, you can do so through the admin interface.
The cron job only processes stories with external URLs. It skips:
This ensures you only generate videos for stories that have actual web content to summarize.
The cron job logs detailed information about its execution:
[HN Cron] Starting HackerNews processing at 2025-10-21T22:00:00.000Z
[HN Cron] Processing top 10 stories
[HN Cron] Retrieved 500 total story IDs
[HN Cron] Processing 10 stories
[HN Cron] Story 12345: Generating video for https://example.com
[HN Cron] Story 12345: Video generation started successfully
[HN Cron] Story 12346: URL already processed, skipping
[HN Cron] Story 12347: No external URL, skipping
[HN Cron] Processing complete:
[HN Cron] - Processed: 3
[HN Cron] - Skipped: 7
[HN Cron] - Errors: 0
You can view these logs in Val.Town's execution logs.
Before setting up the cron schedule, you can test the job manually:
Possible causes:
GEMINI_API_KEY might be missing or invalidSolution: Check the execution logs for specific error messages.
Solution: Reduce the TOP_STORIES_LIMIT constant to a lower number (e.g., 5 instead of 10).
The cron job is designed with cost control in mind:
To further control costs:
TOP_STORIES_LIMIT to a lower numberThe cron job integrates seamlessly with your existing system:
/api/videos/generate)No changes to your existing code are required - the cron job is completely standalone.