Skip to content

Commit

Permalink
Merge pull request #886 from InseeFrLab:env-running-threshold
Browse files Browse the repository at this point in the history
feat: add env var RUNNING_TIME_THRESHOLD #846
  • Loading branch information
garronej authored Nov 25, 2024
2 parents 40e5dc1 + ee69461 commit 0bdea1e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
8 changes: 8 additions & 0 deletions web/.env
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,14 @@ QUOTA_WARNING_THRESHOLD=75%
#
QUOTA_CRITICAL_THRESHOLD=95%

# Services that have been running for too long are displayed on the "My Services" page
# with a warning alerting the user that the service has been running for "too long".
# This parameter allows you to define what "too long" means in your Onyxia instance.
#
# Default: 168 hours (7 days)
#
RUNNING_TIME_THRESHOLD_HOURS=168

# This parameter controls if the configurations tabs should be expanded by default
# when the user navigates to the launcher page:
# https://github.com/InseeFrLab/onyxia/assets/6702424/a1c5597e-82e5-4532-8a9f-ed3ab7cc1d45
Expand Down
15 changes: 14 additions & 1 deletion web/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const { env, injectTransferableEnvsInQueryParams } = createParsedEnvs([
envName: "SPLASHSCREEN_LOGO_SCALE_FACTOR",
isUsedInKeycloakTheme: false,
validateAndParseOrGetDefault: ({ envValue, envName }) => {
assert(envValue !== "Should have default in .env");
assert(envValue !== "", "Should have default in .env");

const parsedValue = Number(envValue);

Expand Down Expand Up @@ -1097,6 +1097,19 @@ export const { env, injectTransferableEnvsInQueryParams } = createParsedEnvs([
return n / 100;
}
},
{
envName: "RUNNING_TIME_THRESHOLD_HOURS",
isUsedInKeycloakTheme: false,
validateAndParseOrGetDefault: ({ envValue, envName }) => {
assert(envValue !== "", "Should have default in .env");

const parsedValue = Number(envValue);

assert(!isNaN(parsedValue), `${envName} is not a number`);

return parsedValue;
}
},
{
envName: "QUOTA_CRITICAL_THRESHOLD",
isUsedInKeycloakTheme: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import type { Service } from "core/usecases/serviceManagement";
import { assert, type Equals } from "tsafe/assert";
import { TextField, TextFieldProps } from "onyxia-ui/TextField";
import MuiLink from "@mui/material/Link";
import { env } from "env";

const runningTimeThreshold = 7 * 24 * 3600 * 1000;
const THRESHOLD_MS = 1000 * 60 * 60 * env.RUNNING_TIME_THRESHOLD_HOURS;

function getDoesHaveBeenRunningForTooLong(params: { startTime: number }): boolean {
const { startTime } = params;

return Date.now() - startTime > runningTimeThreshold;
return Date.now() - startTime > THRESHOLD_MS;
}

export type Props = {
Expand Down
1 change: 1 addition & 0 deletions web/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type ImportMetaEnv = {
SAMPLE_DATASET_URL: string
QUOTA_WARNING_THRESHOLD: string
QUOTA_CRITICAL_THRESHOLD: string
RUNNING_TIME_THRESHOLD_HOURS: string
SERVICE_CONFIGURATION_EXPANDED_BY_DEFAULT: string
S3_DOCUMENTATION_LINK: string
VAULT_DOCUMENTATION_LINK: string
Expand Down

0 comments on commit 0bdea1e

Please sign in to comment.