add limit overrides to runtime definitions

This commit is contained in:
Thomas Hobson 2022-01-31 17:47:27 +13:00
parent 8d6ecfaf37
commit ddab59ccdd
No known key found for this signature in database
GPG Key ID: 9F1FD9D87950DB6F
3 changed files with 20 additions and 26 deletions

View File

@ -46,7 +46,7 @@ const { Job } = require('../job');
...metadata,
...runtime.Runtime.compute_all_limits(
metadata.language,
metadata.limit_overrides
metadata.limitOverrides
),
flake_path: runtime_path,
});

View File

@ -7,7 +7,6 @@ const path = require('path');
const runtimes = [];
class Runtime {
constructor({
language,
@ -23,7 +22,7 @@ class Runtime {
max_process_count,
max_open_files,
max_file_size,
output_max_size
output_max_size,
}) {
this.language = language;
this.runtime = runtime;
@ -45,7 +44,6 @@ class Runtime {
this.package_support = packageSupport;
}
static compute_single_limit(
language_name,
limit_name,
@ -116,18 +114,17 @@ class Runtime {
function _ensure_built(key) {
const command = `nix build ${flake_path}.metadata.${key} --no-link`;
cp.execSync(command, {stdio: "pipe"})
cp.execSync(command, { stdio: 'pipe' });
}
_ensure_built("run");
if(this.compiled) _ensure_built("compile");
logger.debug(`Finished ensuring ${this} is installed`)
_ensure_built('run');
if (this.compiled) _ensure_built('compile');
logger.debug(`Finished ensuring ${this} is installed`);
}
static load_runtime(flake_key) {
logger.info(`Loading ${flake_key}`)
logger.info(`Loading ${flake_key}`);
const flake_path = `${config.flake_path}#pistonRuntimeSets.${config.runtime_set}.${flake_key}`;
const metadata_command = `nix eval --json ${flake_path}.metadata`;
const metadata = JSON.parse(cp.execSync(metadata_command));
@ -136,18 +133,16 @@ class Runtime {
...metadata,
...Runtime.compute_all_limits(
metadata.language,
metadata.limit_overrides
metadata.limitOverrides
),
flake_path
flake_path,
});
this_runtime.ensure_built();
runtimes.push(this_runtime);
logger.debug(`Package ${flake_key} was loaded`);
}
get compiled() {
@ -161,10 +156,8 @@ class Runtime {
toString() {
return `${this.language}-${this.version}`;
}
}
module.exports = runtimes;
module.exports.Runtime = Runtime;
module.exports.load_runtime = Runtime.load_runtime;

View File

@ -21,6 +21,7 @@
compile? null,
packages? null,
aliases? [],
limitOverrides? {},
tests
}: let
compileFile = if compile != null then
@ -28,7 +29,7 @@
else null;
runFile = pkgs.writeShellScript "run" run;
metadata = {
inherit language version runtime aliases;
inherit language version runtime aliases limitOverrides;
run = runFile;
compile = compileFile;
packageSupport = packages != null;