Working state 1

This commit is contained in:
2026-08-09 20:31:03 +00:00
parent e0494df683
commit f522ae9953
14 changed files with 752 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import { NextResponse } from 'next/server';
import { query } from '@/lib/db';
import axios from 'axios';
export async function POST() {
try {
// 1. Alle aktiven Hotels aus der Datenbank holen
const result = await query(
'SELECT id, booking_url FROM hotels WHERE is_active = true'
);
const activeHotels = result.rows;
const scraperUrl = process.env.SCRAPER_API_URL || 'http://localhost:3000/scrape';
const webhookUrl = process.env.APP_WEBHOOK_URL || 'http://localhost:3001/api/webhooks/scraper';
let triggeredCount = 0;
// 2. Pro Hotel einen Scrape-Job an den Scraper-Microservice feuern
for (const hotel of activeHotels) {
await axios.post(scraperUrl, {
url: hotel.booking_url,
webhookUrl: `${webhookUrl}?hotelId=${hotel.id}` // Hotel-ID als URL-Param übergeben
});
triggeredCount++;
}
return NextResponse.json({
success: true,
message: `${triggeredCount} Scrape-Jobs an den Scraper übergeben.`
});
} catch (error: any) {
console.error('Trigger Job Error:', error);
return NextResponse.json({ success: false, error: error.message }, { status: 500 });
}
}