mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-04 17:40:39 +08:00
feat: offload crawl results to the DB
This commit is contained in:
parent
4bbc9db1df
commit
8dbac0268c
@ -4,6 +4,7 @@ import { RateLimiterMode } from "../../src/types";
|
|||||||
import { getScrapeQueue } from "../../src/services/queue-service";
|
import { getScrapeQueue } from "../../src/services/queue-service";
|
||||||
import { Logger } from "../../src/lib/logger";
|
import { Logger } from "../../src/lib/logger";
|
||||||
import { getCrawl, getCrawlJobs } from "../../src/lib/crawl-redis";
|
import { getCrawl, getCrawlJobs } from "../../src/lib/crawl-redis";
|
||||||
|
import { supabaseGetJobById } from "../../src/lib/supabase-jobs";
|
||||||
|
|
||||||
export async function crawlStatusController(req: Request, res: Response) {
|
export async function crawlStatusController(req: Request, res: Response) {
|
||||||
try {
|
try {
|
||||||
@ -21,18 +22,25 @@ export async function crawlStatusController(req: Request, res: Response) {
|
|||||||
return res.status(404).json({ error: "Job not found" });
|
return res.status(404).json({ error: "Job not found" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sc.team_id !== team_id) {
|
||||||
|
return res.status(403).json({ error: "Forbidden" });
|
||||||
|
}
|
||||||
|
|
||||||
const jobIDs = await getCrawlJobs(req.params.jobId);
|
const jobIDs = await getCrawlJobs(req.params.jobId);
|
||||||
|
|
||||||
// let data = job.returnvalue;
|
const jobs = await Promise.all(jobIDs.map(async x => {
|
||||||
// if (process.env.USE_DB_AUTHENTICATION === "true") {
|
const job = await getScrapeQueue().getJob(x);
|
||||||
// const supabaseData = await supabaseGetJobById(req.params.jobId);
|
|
||||||
|
|
||||||
// if (supabaseData) {
|
if (process.env.USE_DB_AUTHENTICATION === "true") {
|
||||||
// data = supabaseData.docs;
|
const supabaseData = await supabaseGetJobById(job.id);
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
const jobs = await Promise.all(jobIDs.map(x => getScrapeQueue().getJob(x)));
|
if (supabaseData) {
|
||||||
|
job.returnvalue = supabaseData.docs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return job;
|
||||||
|
}));
|
||||||
const jobStatuses = await Promise.all(jobs.map(x => x.getState()));
|
const jobStatuses = await Promise.all(jobs.map(x => x.getState()));
|
||||||
const jobStatus = sc.cancelled ? "failed" : jobStatuses.every(x => x === "completed") ? "completed" : jobStatuses.some(x => x === "failed") ? "failed" : "active";
|
const jobStatus = sc.cancelled ? "failed" : jobStatuses.every(x => x === "completed") ? "completed" : jobStatuses.some(x => x === "failed") ? "failed" : "active";
|
||||||
|
|
||||||
|
@ -53,7 +53,11 @@ const processJobInternal = async (token: string, job: Job) => {
|
|||||||
try {
|
try {
|
||||||
const result = await processJob(job, token);
|
const result = await processJob(job, token);
|
||||||
try{
|
try{
|
||||||
|
if (job.data.crawl_id && process.env.USE_DB_AUTHENTICATION === "true") {
|
||||||
|
await job.moveToCompleted(null, token, false);
|
||||||
|
} else {
|
||||||
await job.moveToCompleted(result.docs, token, false);
|
await job.moveToCompleted(result.docs, token, false);
|
||||||
|
}
|
||||||
}catch(e){
|
}catch(e){
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user