Browse Source
Nostr-Signature: 42c1a2a63a4568c65d82d78701451b3b4363bdf9c8c57e804535b5f3f0d7b6fc 573634b648634cbad10f2451776089ea21090d9407f715e83c577b4611ae6edc 8e5f32ecb79da876ac41eba04c3b1541b21d039ae50d1b9fefa630d35f31c97dd29af64e4b695742fa7d4eaec17db8f4a066b4db99ce628aed596971975d4a87main
9 changed files with 156 additions and 225 deletions
@ -0,0 +1,30 @@ |
|||||||
|
/** |
||||||
|
* Shared utility for triggering repo polls |
||||||
|
* This provides a consistent interface for triggering polls from anywhere in the codebase |
||||||
|
*/ |
||||||
|
|
||||||
|
import { getRepoPollingService } from '../services/service-registry.js'; |
||||||
|
import logger from '../services/logger.js'; |
||||||
|
|
||||||
|
/** |
||||||
|
* Trigger a repo poll |
||||||
|
* This is the single source of truth for triggering polls |
||||||
|
* @param context Optional context string for logging (e.g., 'user-verification', 'manual-refresh') |
||||||
|
* @returns Promise that resolves when poll is triggered (not when it completes) |
||||||
|
*/ |
||||||
|
export async function triggerRepoPoll(context?: string): Promise<void> { |
||||||
|
const pollingService = getRepoPollingService(); |
||||||
|
|
||||||
|
if (!pollingService) { |
||||||
|
logger.warn({ context }, 'Poll request received but polling service not initialized'); |
||||||
|
throw new Error('Polling service not available'); |
||||||
|
} |
||||||
|
|
||||||
|
// Trigger poll asynchronously (non-blocking)
|
||||||
|
// The poll will complete in the background
|
||||||
|
pollingService.triggerPoll().catch((err) => { |
||||||
|
logger.error({ error: err, context }, 'Failed to trigger poll'); |
||||||
|
}); |
||||||
|
|
||||||
|
logger.info({ context }, 'Repo poll triggered'); |
||||||
|
} |
||||||
@ -0,0 +1,33 @@ |
|||||||
|
/** |
||||||
|
* API endpoint for manually triggering a repo poll |
||||||
|
* This allows users to refresh the repo list and trigger provisioning of new repos |
||||||
|
*
|
||||||
|
* This is the public API interface for triggering polls. |
||||||
|
* All poll triggers should go through this endpoint or the shared triggerRepoPoll utility. |
||||||
|
*/ |
||||||
|
|
||||||
|
import { json } from '@sveltejs/kit'; |
||||||
|
import type { RequestHandler } from './$types'; |
||||||
|
import { triggerRepoPoll } from '$lib/utils/repo-poll-trigger.js'; |
||||||
|
import { extractRequestContext } from '$lib/utils/api-context.js'; |
||||||
|
|
||||||
|
export const POST: RequestHandler = async (event) => { |
||||||
|
const requestContext = extractRequestContext(event); |
||||||
|
const clientIp = requestContext.clientIp || 'unknown'; |
||||||
|
|
||||||
|
try { |
||||||
|
await triggerRepoPoll('api-endpoint'); |
||||||
|
|
||||||
|
return json({
|
||||||
|
success: true, |
||||||
|
message: 'Poll triggered successfully' |
||||||
|
}); |
||||||
|
} catch (err) { |
||||||
|
const errorMessage = err instanceof Error ? err.message : String(err); |
||||||
|
|
||||||
|
return json({
|
||||||
|
success: false,
|
||||||
|
error: errorMessage
|
||||||
|
}, { status: err instanceof Error && errorMessage.includes('not available') ? 503 : 500 }); |
||||||
|
} |
||||||
|
}; |
||||||
Loading…
Reference in new issue