Working state 1
This commit is contained in:
36
src/app/api/jobs/trigger-daily-check/route.ts
Normal file
36
src/app/api/jobs/trigger-daily-check/route.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user