mirror of
https://github.com/wassname/talk.git
synced 2026-07-20 12:40:47 +08:00
feat: added config variable for perspective timeout (#2817)
Added a configuration timeout variable for changing the perspective timeout number.
This commit is contained in:
@@ -51,9 +51,15 @@ convict.addFormat({
|
||||
convict.addFormat({
|
||||
name: "ms",
|
||||
validate: (val: number) => {
|
||||
Joi.assert(val, Joi.number().min(0));
|
||||
Joi.assert(
|
||||
val,
|
||||
Joi.number()
|
||||
.positive()
|
||||
.integer()
|
||||
.required()
|
||||
);
|
||||
},
|
||||
coerce: (val: string) => ms(val),
|
||||
coerce: (val: string): number => ms(val),
|
||||
});
|
||||
|
||||
const algorithms = [
|
||||
@@ -255,6 +261,14 @@ const config = convict({
|
||||
env: "SCRAPE_TIMEOUT",
|
||||
arg: "scrapeTimeout",
|
||||
},
|
||||
perspective_timeout: {
|
||||
doc:
|
||||
"The request timeout (in ms) for perspective comment checking operations.",
|
||||
format: "ms",
|
||||
default: "800 milliseconds",
|
||||
env: "PERSPECTIVE_TIMEOUT",
|
||||
arg: "perspectiveTimeout",
|
||||
},
|
||||
disable_force_ssl: {
|
||||
doc:
|
||||
"Disables forcing SSL in production environments. Should not be used except for testing.",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { isNil } from "lodash";
|
||||
import ms from "ms";
|
||||
import fetch from "node-fetch";
|
||||
import path from "path";
|
||||
import { URL } from "url";
|
||||
@@ -32,12 +31,13 @@ export const toxic: IntermediateModerationPhase = async ({
|
||||
nudge,
|
||||
log,
|
||||
htmlStripped,
|
||||
config,
|
||||
// FEATURE_FLAG:DISABLE_WARN_USER_OF_TOXIC_COMMENT
|
||||
comment: { body },
|
||||
}: Pick<
|
||||
ModerationPhaseContext,
|
||||
// FEATURE_FLAG:DISABLE_WARN_USER_OF_TOXIC_COMMENT
|
||||
"tenant" | "nudge" | "log" | "htmlStripped" | "comment"
|
||||
"tenant" | "nudge" | "log" | "htmlStripped" | "comment" | "config"
|
||||
>): Promise<IntermediatePhaseResult | void> => {
|
||||
if (!htmlStripped) {
|
||||
return;
|
||||
@@ -89,8 +89,9 @@ export const toxic: IntermediateModerationPhase = async ({
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: (wyattjoh) replace hardcoded default with config.
|
||||
const timeout = ms("800ms");
|
||||
// This typecast is needed because the custom `ms` format does not return the
|
||||
// desired `number` type even though that's the only type it can output.
|
||||
const timeout = (config.get("perspective_timeout") as unknown) as number;
|
||||
|
||||
try {
|
||||
// FEATURE_FLAG:DISABLE_WARN_USER_OF_TOXIC_COMMENT
|
||||
|
||||
Reference in New Issue
Block a user