mirror of
https://github.com/engineer-man/piston.git
synced 2025-05-05 19:36:26 +02:00
fix: added incremental typing to piston
This commit is contained in:
parent
593f59a184
commit
2962e0cf99
14 changed files with 1039 additions and 1318 deletions
|
@ -1,6 +1,6 @@
|
|||
const fss = require('fs');
|
||||
const Logger = require('logplease');
|
||||
const logger = Logger.create('config');
|
||||
import { existsSync } from 'fs';
|
||||
import { create, LogLevels } from 'logplease';
|
||||
const logger = create('config', {});
|
||||
|
||||
const options = {
|
||||
log_level: {
|
||||
|
@ -8,7 +8,7 @@ const options = {
|
|||
default: 'INFO',
|
||||
validators: [
|
||||
x =>
|
||||
Object.values(Logger.LogLevels).includes(x) ||
|
||||
Object.values(LogLevels).includes(x) ||
|
||||
`Log level ${x} does not exist`,
|
||||
],
|
||||
},
|
||||
|
@ -20,33 +20,31 @@ const options = {
|
|||
data_directory: {
|
||||
desc: 'Absolute path to store all piston related data at',
|
||||
default: '/piston',
|
||||
validators: [
|
||||
x => fss.exists_sync(x) || `Directory ${x} does not exist`,
|
||||
],
|
||||
validators: [x => existsSync(x) || `Directory ${x} does not exist`],
|
||||
},
|
||||
runner_uid_min: {
|
||||
desc: 'Minimum uid to use for runner',
|
||||
default: 1001,
|
||||
parser: parse_int,
|
||||
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||
parser: parseInt,
|
||||
validators: [(x, raw) => !isNaN(x) || `${raw} is not a number`],
|
||||
},
|
||||
runner_uid_max: {
|
||||
desc: 'Maximum uid to use for runner',
|
||||
default: 1500,
|
||||
parser: parse_int,
|
||||
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||
parser: parseInt,
|
||||
validators: [(x, raw) => !isNaN(x) || `${raw} is not a number`],
|
||||
},
|
||||
runner_gid_min: {
|
||||
desc: 'Minimum gid to use for runner',
|
||||
default: 1001,
|
||||
parser: parse_int,
|
||||
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||
parser: parseInt,
|
||||
validators: [(x, raw) => !isNaN(x) || `${raw} is not a number`],
|
||||
},
|
||||
runner_gid_max: {
|
||||
desc: 'Maximum gid to use for runner',
|
||||
default: 1500,
|
||||
parser: parse_int,
|
||||
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||
parser: parseInt,
|
||||
validators: [(x, raw) => !isNaN(x) || `${raw} is not a number`],
|
||||
},
|
||||
disable_networking: {
|
||||
desc: 'Set to true to disable networking',
|
||||
|
@ -57,50 +55,50 @@ const options = {
|
|||
output_max_size: {
|
||||
desc: 'Max size of each stdio buffer',
|
||||
default: 1024,
|
||||
parser: parse_int,
|
||||
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||
parser: parseInt,
|
||||
validators: [(x, raw) => !isNaN(x) || `${raw} is not a number`],
|
||||
},
|
||||
max_process_count: {
|
||||
desc: 'Max number of processes per job',
|
||||
default: 64,
|
||||
parser: parse_int,
|
||||
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||
parser: parseInt,
|
||||
validators: [(x, raw) => !isNaN(x) || `${raw} is not a number`],
|
||||
},
|
||||
max_open_files: {
|
||||
desc: 'Max number of open files per job',
|
||||
default: 2048,
|
||||
parser: parse_int,
|
||||
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||
parser: parseInt,
|
||||
validators: [(x, raw) => !isNaN(x) || `${raw} is not a number`],
|
||||
},
|
||||
max_file_size: {
|
||||
desc: 'Max file size in bytes for a file',
|
||||
default: 10000000, //10MB
|
||||
parser: parse_int,
|
||||
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||
parser: parseInt,
|
||||
validators: [(x, raw) => !isNaN(x) || `${raw} is not a number`],
|
||||
},
|
||||
compile_timeout: {
|
||||
desc: 'Max time allowed for compile stage in milliseconds',
|
||||
default: 10000, // 10 seconds
|
||||
parser: parse_int,
|
||||
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||
parser: parseInt,
|
||||
validators: [(x, raw) => !isNaN(x) || `${raw} is not a number`],
|
||||
},
|
||||
run_timeout: {
|
||||
desc: 'Max time allowed for run stage in milliseconds',
|
||||
default: 3000, // 3 seconds
|
||||
parser: parse_int,
|
||||
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||
parser: parseInt,
|
||||
validators: [(x, raw) => !isNaN(x) || `${raw} is not a number`],
|
||||
},
|
||||
compile_memory_limit: {
|
||||
desc: 'Max memory usage for compile stage in bytes (set to -1 for no limit)',
|
||||
default: -1, // no limit
|
||||
parser: parse_int,
|
||||
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||
parser: parseInt,
|
||||
validators: [(x, raw) => !isNaN(x) || `${raw} is not a number`],
|
||||
},
|
||||
run_memory_limit: {
|
||||
desc: 'Max memory usage for run stage in bytes (set to -1 for no limit)',
|
||||
default: -1, // no limit
|
||||
parser: parse_int,
|
||||
validators: [(x, raw) => !is_nan(x) || `${raw} is not a number`],
|
||||
parser: parseInt,
|
||||
validators: [(x, raw) => !isNaN(x) || `${raw} is not a number`],
|
||||
},
|
||||
repo_url: {
|
||||
desc: 'URL of repo index',
|
||||
|
@ -111,7 +109,7 @@ const options = {
|
|||
max_concurrent_jobs: {
|
||||
desc: 'Maximum number of concurrent jobs to run at one time',
|
||||
default: 64,
|
||||
parser: parse_int,
|
||||
parser: parseInt,
|
||||
validators: [x => x > 0 || `${x} cannot be negative`],
|
||||
},
|
||||
limit_overrides: {
|
||||
|
@ -201,12 +199,14 @@ function validate_overrides(overrides) {
|
|||
|
||||
logger.info(`Loading Configuration from environment`);
|
||||
|
||||
/** @type {import('./types').ObjectType<typeof options, "default">} */
|
||||
// @ts-ignore
|
||||
let config = {};
|
||||
|
||||
for (const option_name in options) {
|
||||
const env_key = 'PISTON_' + option_name.to_upper_case();
|
||||
const env_key = 'PISTON_' + option_name.toUpperCase();
|
||||
const option = options[option_name];
|
||||
const parser = option.parser || (x => x);
|
||||
const parser = option.parser || ((/** @type {any} */ x) => x);
|
||||
const env_val = process.env[env_key];
|
||||
const parsed_val = parser(env_val);
|
||||
const value = env_val === undefined ? option.default : parsed_val;
|
||||
|
@ -228,4 +228,4 @@ for (const option_name in options) {
|
|||
|
||||
logger.info('Configuration successfully loaded');
|
||||
|
||||
module.exports = config;
|
||||
export default config;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue