• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
paulkinlan

paulkinlan

veo-feed

Public
Like
veo-feed
Home
Code
11
backend
3
frontend
5
shared
2
.vtignore
AGENTS.md
HACKERNEWS_CRON_SETUP.md
README.md
deno.json
C
hackernews-cron.ts
test-db.ts
test-polling.ts
Branches
1
Pull requests
Remixes
History
Environment variables
4
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
HACKERNEWS_CRON_SETUP.md
Code
/
HACKERNEWS_CRON_SETUP.md
Search
10/21/2025
HACKERNEWS_CRON_SETUP.md

HackerNews Cron Job Setup Guide

This document explains how to set up the HackerNews cron job on Val.Town.

Overview

The hackernews-cron.ts file contains a cron job that:

  • Runs every hour
  • Fetches the top 10 HackerNews stories
  • Automatically generates videos for new URLs (no duplicates)
  • Uses your default video generation prompt
  • Skips text posts (Ask HN, Show HN, etc.) - only processes external URLs

Setup Instructions

1. Upload the Cron Job to Val.Town

  1. Go to Val.Town
  2. Create a new Val
  3. Copy the contents of hackernews-cron.ts into the Val
  4. Save the Val

2. Configure Environment Variables

The 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.

3. Set Up the Cron Schedule

In Val.Town:

  1. Click on the "Schedule" button in your Val
  2. Set the schedule to run every hour: 0 * * * * (cron syntax)
  3. Save the schedule

4. Configuration Options

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 stories
  • 50 - Top 50 stories
  • 100 - Top 100 stories

How It Works

Workflow

  1. Fetch Stories: The cron job fetches the list of top story IDs from HackerNews
  2. Get Story Details: For each story (up to TOP_STORIES_LIMIT), it fetches the full story details
  3. Filter: It filters out:
    • Stories without external URLs (text posts, Ask HN, Show HN)
    • URLs that already exist in the database (duplicates)
  4. Generate Videos: For each new URL, it directly calls the generateVideoAsync() function with the default prompt
  5. Log Results: It logs a summary of processed, skipped, and failed stories

Duplicate Prevention

The cron job uses the getVideoByUrl() database query to check if a URL has already been processed. This ensures:

  • Cost control: You don't regenerate videos for the same URL
  • Efficiency: No wasted API calls or processing time
  • Data integrity: Each URL is only processed once

Note: If you want to regenerate a video for a URL, you can do so through the admin interface.

External URL Filter

The cron job only processes stories with external URLs. It skips:

  • Ask HN posts (text-only discussions)
  • Show HN posts without URLs
  • Job postings without URLs
  • Any other text-only content

This ensures you only generate videos for stories that have actual web content to summarize.

Monitoring

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.

Testing

Before setting up the cron schedule, you can test the job manually:

  1. In Val.Town, open your cron job Val
  2. Click the "Run" button to execute it immediately
  3. Check the logs to see the results
  4. Verify that videos are being generated in your application

Troubleshooting

"No videos are being generated"

Possible causes:

  1. All URLs might already be in the database (check logs for "duplicate" messages)
  2. All stories might be text posts without URLs (check logs for "no URL" messages)
  3. The GEMINI_API_KEY might be missing or invalid

Solution: Check the execution logs for specific error messages.

"Too many videos being generated"

Solution: Reduce the TOP_STORIES_LIMIT constant to a lower number (e.g., 5 instead of 10).

Cost Management

The cron job is designed with cost control in mind:

  1. Configurable limit: Easy to adjust the number of stories processed
  2. Duplicate prevention: Never processes the same URL twice
  3. Efficient filtering: Skips text posts before making API calls
  4. Batched processing: All video generations are triggered at once, then processed asynchronously

To further control costs:

  • Set TOP_STORIES_LIMIT to a lower number
  • Run the cron less frequently (e.g., every 2-3 hours instead of hourly)
  • Monitor the logs to see how many new stories are typically found

Integration with Existing System

The cron job integrates seamlessly with your existing system:

  • Uses the same video generation endpoint (/api/videos/generate)
  • Leverages the existing database schema and queries
  • Works with the existing polling mechanism for video completion
  • Respects the default video prompt from your configuration
  • Videos can be managed through the admin interface like any other video

No changes to your existing code are required - the cron job is completely standalone.

FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
Β© 2025 Val Town, Inc.