mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-12 01:59:04 +08:00
fix(scrape): bill llm on fail
This commit is contained in:
parent
b35462456e
commit
0e027fe430
@ -74,6 +74,35 @@ export async function scrapeController(
|
||||
scrapeId: jobId,
|
||||
startTime,
|
||||
});
|
||||
|
||||
let creditsToBeBilled = 0;
|
||||
|
||||
if (req.body.agent?.model?.toLowerCase() === "fire-1" || req.body.extract?.agent?.model?.toLowerCase() === "fire-1" || req.body.jsonOptions?.agent?.model?.toLowerCase() === "fire-1") {
|
||||
if (process.env.USE_DB_AUTHENTICATION === "true") {
|
||||
// @Nick this is a hack pushed at 2AM pls help - mogery
|
||||
const job = await supabaseGetJobById(jobId);
|
||||
if (!job?.cost_tracking) {
|
||||
logger.warn("No cost tracking found for job", {
|
||||
jobId,
|
||||
});
|
||||
}
|
||||
creditsToBeBilled = Math.ceil((job?.cost_tracking?.totalCost ?? 1) * 1800);
|
||||
} else {
|
||||
creditsToBeBilled = 150;
|
||||
}
|
||||
}
|
||||
|
||||
if (creditsToBeBilled > 0) {
|
||||
billTeam(req.auth.team_id, req.acuc?.sub_id, creditsToBeBilled).catch(
|
||||
(error) => {
|
||||
logger.error(
|
||||
`Failed to bill team ${req.auth.team_id} for ${creditsToBeBilled} credits: ${error}`,
|
||||
);
|
||||
// Optionally, you could notify an admin or add to a retry queue here
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
e instanceof Error &&
|
||||
(e.message.startsWith("Job wait") || e.message === "timeout")
|
||||
|
Loading…
x
Reference in New Issue
Block a user