mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-04-18 12:09:42 +08:00
tally rework api switchover (#1328)
* tally rework api switchover * fix and send logs * temp: force main instance while RPCs propagate * Revert "temp: force main instance while RPCs propagate" This reverts commit 4c93379cfa64efd60eb4767dd8eced1bdd302531.
This commit is contained in:
parent
7cf2e52fe6
commit
71b6b83ec2
12
.github/workflows/test-server.yml
vendored
12
.github/workflows/test-server.yml
vendored
@ -89,4 +89,14 @@ jobs:
|
|||||||
- name: Run snippet tests
|
- name: Run snippet tests
|
||||||
run: |
|
run: |
|
||||||
npm run test:snips
|
npm run test:snips
|
||||||
working-directory: ./apps/api
|
working-directory: ./apps/api
|
||||||
|
- name: Kill instances
|
||||||
|
if: always()
|
||||||
|
run: pkill -9 node
|
||||||
|
# - uses: actions/upload-artifact@v4
|
||||||
|
# if: always()
|
||||||
|
# with:
|
||||||
|
# name: Logs
|
||||||
|
# path: |
|
||||||
|
# ./apps/api/api.log
|
||||||
|
# ./apps/api/worker.log
|
@ -236,10 +236,16 @@ export async function search(body: SearchRequestInput): Promise<Document[]> {
|
|||||||
// =========================================
|
// =========================================
|
||||||
|
|
||||||
export async function creditUsage(): Promise<{ remaining_credits: number }> {
|
export async function creditUsage(): Promise<{ remaining_credits: number }> {
|
||||||
return (await request(TEST_URL)
|
const req = (await request(TEST_URL)
|
||||||
.get("/v1/team/credit-usage")
|
.get("/v1/team/credit-usage")
|
||||||
.set("Authorization", `Bearer ${process.env.TEST_API_KEY}`)
|
.set("Authorization", `Bearer ${process.env.TEST_API_KEY}`)
|
||||||
.set("Content-Type", "application/json")).body.data;
|
.set("Content-Type", "application/json"));
|
||||||
|
|
||||||
|
if (req.status !== 200) {
|
||||||
|
throw req.body;
|
||||||
|
}
|
||||||
|
|
||||||
|
return req.body.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function tokenUsage(): Promise<{ remaining_tokens: number }> {
|
export async function tokenUsage(): Promise<{ remaining_tokens: number }> {
|
||||||
|
@ -96,15 +96,12 @@ export async function getACUC(
|
|||||||
let isExtract =
|
let isExtract =
|
||||||
mode === RateLimiterMode.Extract ||
|
mode === RateLimiterMode.Extract ||
|
||||||
mode === RateLimiterMode.ExtractStatus;
|
mode === RateLimiterMode.ExtractStatus;
|
||||||
let rpcName = isExtract
|
|
||||||
? "auth_credit_usage_chunk_extract"
|
|
||||||
: "auth_credit_usage_chunk_test_22_credit_pack_n_extract";
|
|
||||||
while (retries < maxRetries) {
|
while (retries < maxRetries) {
|
||||||
const client =
|
const client =
|
||||||
Math.random() > (2/3) ? supabase_rr_service : supabase_service;
|
Math.random() > (2/3) ? supabase_rr_service : supabase_service;
|
||||||
({ data, error } = await client.rpc(
|
({ data, error } = await client.rpc(
|
||||||
rpcName,
|
"auth_credit_usage_chunk_23_tally",
|
||||||
{ input_key: api_key },
|
{ input_key: api_key, i_is_extract: isExtract, tally_untallied_credits: true },
|
||||||
{ get: true },
|
{ get: true },
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -114,6 +111,7 @@ export async function getACUC(
|
|||||||
|
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Failed to retrieve authentication and credit usage data after ${retries}, trying again...`,
|
`Failed to retrieve authentication and credit usage data after ${retries}, trying again...`,
|
||||||
|
{ error }
|
||||||
);
|
);
|
||||||
retries++;
|
retries++;
|
||||||
if (retries === maxRetries) {
|
if (retries === maxRetries) {
|
||||||
|
@ -10,8 +10,8 @@ import { getACUC, setCachedACUC } from "../../controllers/auth";
|
|||||||
const BATCH_KEY = "billing_batch";
|
const BATCH_KEY = "billing_batch";
|
||||||
const BATCH_LOCK_KEY = "billing_batch_lock";
|
const BATCH_LOCK_KEY = "billing_batch_lock";
|
||||||
const BATCH_SIZE = 50; // Batch size for processing
|
const BATCH_SIZE = 50; // Batch size for processing
|
||||||
const BATCH_TIMEOUT = 30000; // 15 seconds processing interval
|
const BATCH_TIMEOUT = 15000; // 15 seconds processing interval
|
||||||
const LOCK_TIMEOUT = 60000; // 30 seconds lock timeout
|
const LOCK_TIMEOUT = 30000; // 30 seconds lock timeout
|
||||||
|
|
||||||
// Define interfaces for billing operations
|
// Define interfaces for billing operations
|
||||||
interface BillingOperation {
|
interface BillingOperation {
|
||||||
@ -281,7 +281,7 @@ async function supaBillTeam(
|
|||||||
_logger.info(`Batch billing team ${team_id} for ${credits} credits`);
|
_logger.info(`Batch billing team ${team_id} for ${credits} credits`);
|
||||||
|
|
||||||
// Perform the actual database operation
|
// Perform the actual database operation
|
||||||
const { data, error } = await supabase_service.rpc("bill_team_w_extract_3", {
|
const { data, error } = await supabase_service.rpc("bill_team_4_tally", {
|
||||||
_team_id: team_id,
|
_team_id: team_id,
|
||||||
sub_id: subscription_id ?? null,
|
sub_id: subscription_id ?? null,
|
||||||
fetch_subscription: subscription_id === undefined,
|
fetch_subscription: subscription_id === undefined,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user