mirror of
https://git.mirrors.martin98.com/https://github.com/jina-ai/reader
synced 2025-08-15 02:15:56 +08:00
fix: race condition while logging chargeAmount
This commit is contained in:
parent
6f4819bc49
commit
8b0916f858
@ -425,9 +425,7 @@ ${this.content}
|
|||||||
auth.reportUsage(chargeAmount, 'reader-crawl').catch((err) => {
|
auth.reportUsage(chargeAmount, 'reader-crawl').catch((err) => {
|
||||||
this.logger.warn(`Unable to report usage for ${uid}`, { err: marshalErrorLike(err) });
|
this.logger.warn(`Unable to report usage for ${uid}`, { err: marshalErrorLike(err) });
|
||||||
});
|
});
|
||||||
apiRoll._ref?.set({
|
apiRoll.chargeAmount = chargeAmount;
|
||||||
chargeAmount,
|
|
||||||
}, { merge: true }).catch((err) => this.logger.warn(`Failed to log charge amount in apiRoll`, { err }));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (ctx.req.ip) {
|
} else if (ctx.req.ip) {
|
||||||
@ -724,7 +722,7 @@ ${this.content}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getChargeAmount(formatted: { [k: string]: any; }) {
|
getChargeAmount(formatted: FormattedPage) {
|
||||||
if (!formatted) {
|
if (!formatted) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@ -735,7 +733,7 @@ ${this.content}
|
|||||||
return estimateToken(textContent);
|
return estimateToken(textContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
const imageContent = formatted.screenshotUrl || formatted?.screenshot;
|
const imageContent = formatted.screenshotUrl || (formatted as any)?.screenshot;
|
||||||
|
|
||||||
if (imageContent) {
|
if (imageContent) {
|
||||||
// OpenAI image token count for 1024x1024 image
|
// OpenAI image token count for 1024x1024 image
|
||||||
|
@ -169,9 +169,7 @@ export class SearcherHost extends RPCHost {
|
|||||||
auth.reportUsage(chargeAmount, 'reader-search').catch((err) => {
|
auth.reportUsage(chargeAmount, 'reader-search').catch((err) => {
|
||||||
this.logger.warn(`Unable to report usage for ${uid}`, { err: marshalErrorLike(err) });
|
this.logger.warn(`Unable to report usage for ${uid}`, { err: marshalErrorLike(err) });
|
||||||
});
|
});
|
||||||
apiRoll._ref?.set({
|
apiRoll.chargeAmount = chargeAmount;
|
||||||
chargeAmount,
|
|
||||||
}, { merge: true }).catch((err) => this.logger.warn(`Failed to log charge amount in apiRoll`, { err }));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (ctx.req.ip) {
|
} else if (ctx.req.ip) {
|
||||||
@ -184,9 +182,7 @@ export class SearcherHost extends RPCHost {
|
|||||||
);
|
);
|
||||||
rpcReflect.finally(() => {
|
rpcReflect.finally(() => {
|
||||||
if (chargeAmount) {
|
if (chargeAmount) {
|
||||||
apiRoll._ref?.set({
|
apiRoll.chargeAmount = chargeAmount;
|
||||||
chargeAmount,
|
|
||||||
}, { merge: true }).catch((err) => this.logger.warn(`Failed to log charge amount in apiRoll`, { err }));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -415,7 +411,7 @@ ${this.content}
|
|||||||
return resultArray;
|
return resultArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
getChargeAmount(formatted: any[]) {
|
getChargeAmount(formatted: FormattedPage[]) {
|
||||||
return _.sum(
|
return _.sum(
|
||||||
formatted.map((x) => this.crawler.getChargeAmount(x) || 0)
|
formatted.map((x) => this.crawler.getChargeAmount(x) || 0)
|
||||||
);
|
);
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 2f2cdcff7b2738be33ee5aca858ef2d65eba29ed
|
Subproject commit fc3545e3a7ae27968e69f351f109d3ffb535f963
|
Loading…
x
Reference in New Issue
Block a user