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:
Gergő Móricz 2025-03-12 20:10:33 +01:00 committed by GitHub
parent 7cf2e52fe6
commit 71b6b83ec2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 13 deletions

View File

@ -89,4 +89,14 @@ jobs:
- name: Run snippet tests
run: |
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

View File

@ -236,10 +236,16 @@ export async function search(body: SearchRequestInput): Promise<Document[]> {
// =========================================
export async function creditUsage(): Promise<{ remaining_credits: number }> {
return (await request(TEST_URL)
.get("/v1/team/credit-usage")
.set("Authorization", `Bearer ${process.env.TEST_API_KEY}`)
.set("Content-Type", "application/json")).body.data;
const req = (await request(TEST_URL)
.get("/v1/team/credit-usage")
.set("Authorization", `Bearer ${process.env.TEST_API_KEY}`)
.set("Content-Type", "application/json"));
if (req.status !== 200) {
throw req.body;
}
return req.body.data;
}
export async function tokenUsage(): Promise<{ remaining_tokens: number }> {

View File

@ -96,15 +96,12 @@ export async function getACUC(
let isExtract =
mode === RateLimiterMode.Extract ||
mode === RateLimiterMode.ExtractStatus;
let rpcName = isExtract
? "auth_credit_usage_chunk_extract"
: "auth_credit_usage_chunk_test_22_credit_pack_n_extract";
while (retries < maxRetries) {
const client =
Math.random() > (2/3) ? supabase_rr_service : supabase_service;
({ data, error } = await client.rpc(
rpcName,
{ input_key: api_key },
"auth_credit_usage_chunk_23_tally",
{ input_key: api_key, i_is_extract: isExtract, tally_untallied_credits: true },
{ get: true },
));
@ -114,6 +111,7 @@ export async function getACUC(
logger.warn(
`Failed to retrieve authentication and credit usage data after ${retries}, trying again...`,
{ error }
);
retries++;
if (retries === maxRetries) {

View File

@ -10,8 +10,8 @@ import { getACUC, setCachedACUC } from "../../controllers/auth";
const BATCH_KEY = "billing_batch";
const BATCH_LOCK_KEY = "billing_batch_lock";
const BATCH_SIZE = 50; // Batch size for processing
const BATCH_TIMEOUT = 30000; // 15 seconds processing interval
const LOCK_TIMEOUT = 60000; // 30 seconds lock timeout
const BATCH_TIMEOUT = 15000; // 15 seconds processing interval
const LOCK_TIMEOUT = 30000; // 30 seconds lock timeout
// Define interfaces for billing operations
interface BillingOperation {
@ -281,7 +281,7 @@ async function supaBillTeam(
_logger.info(`Batch billing team ${team_id} for ${credits} credits`);
// 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,
sub_id: subscription_id ?? null,
fetch_subscription: subscription_id === undefined,