Files
firecrawl/apps/api/src/controllers/v1/concurrency-check.ts
T

28 lines
789 B
TypeScript
Raw Normal View History

2024-10-01 16:04:39 -03:00
import {
ConcurrencyCheckParams,
ConcurrencyCheckResponse,
2024-12-11 19:51:08 -03:00
RequestWithAuth,
2024-10-01 16:04:39 -03:00
} from "./types";
import { Response } from "express";
import { redisEvictConnection } from "../../../src/services/redis";
2024-10-01 16:04:39 -03:00
// Basically just middleware and error wrapping
export async function concurrencyCheckController(
req: RequestWithAuth<ConcurrencyCheckParams, undefined, undefined>,
2024-12-11 19:51:08 -03:00
res: Response<ConcurrencyCheckResponse>,
2024-10-01 16:04:39 -03:00
) {
const concurrencyLimiterKey = "concurrency-limiter:" + req.auth.team_id;
2024-10-01 16:04:39 -03:00
const now = Date.now();
const activeJobsOfTeam = await redisEvictConnection.zrangebyscore(
2024-10-01 16:04:39 -03:00
concurrencyLimiterKey,
now,
2024-12-11 19:51:08 -03:00
Infinity,
2024-10-01 16:04:39 -03:00
);
return res.status(200).json({
success: true,
concurrency: activeJobsOfTeam.length,
2025-04-10 18:49:23 +02:00
maxConcurrency: req.acuc.concurrency,
});
2024-10-01 16:04:39 -03:00
}