initial commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
type WebhookPayload = {
|
||||
status: "RUNNING" | "DONE" | "FAILED";
|
||||
progress_pct: number;
|
||||
current_message: string;
|
||||
output_data?: { output_path: string };
|
||||
error_message?: string;
|
||||
started_at?: string;
|
||||
finished_at?: string;
|
||||
};
|
||||
|
||||
const WEBHOOK_TIMEOUT_MS = 10_000;
|
||||
|
||||
export async function sendWebhook(
|
||||
callbackUrl: string,
|
||||
payload: WebhookPayload,
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
const resp = await fetch(callbackUrl, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
signal: AbortSignal.timeout(WEBHOOK_TIMEOUT_MS),
|
||||
});
|
||||
if (!resp.ok) {
|
||||
const responseBody = await resp.text().catch(() => "");
|
||||
console.error(
|
||||
`Webhook POST to ${callbackUrl} returned ${resp.status}: ${resp.statusText}${responseBody ? `\n${responseBody.slice(0, 1000)}` : ""}`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error(`Webhook POST to ${callbackUrl} failed:`, err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user