diff --git a/src/api/programs.rs b/src/api/programs.rs index 8122389..d651d95 100644 --- a/src/api/programs.rs +++ b/src/api/programs.rs @@ -40,6 +40,7 @@ impl ProgramsApi { let ( BuildResult { program_id, + ttl, compile_result, }, read_guard, @@ -77,6 +78,7 @@ impl ProgramsApi { { Ok(run_result) => BuildRun::ok(BuildRunResult { program_id, + ttl, build: compile_result, run: run_result, }), diff --git a/src/program.rs b/src/program.rs index 4e84a9b..0649f18 100644 --- a/src/program.rs +++ b/src/program.rs @@ -47,13 +47,13 @@ pub async fn build_program( let path = config.programs_dir.join(id.to_string()); let _guard = program_lock.read(id).await; - if let Some(cached) = get_cached_program(id, &path, env).await? { + if let Some(cached) = get_cached_program(id, &path, &config, env).await? { return Ok((cached, _guard)); } drop(_guard); let _guard = program_lock.write(id).await; - if let Some(cached) = get_cached_program(id, &path, env).await? { + if let Some(cached) = get_cached_program(id, &path, &config, env).await? { return Ok((cached, _guard.downgrade())); } @@ -67,6 +67,7 @@ pub async fn build_program( Ok(( BuildResult { program_id: id, + ttl: config.program_ttl, compile_result: result, }, _guard.downgrade(), @@ -84,6 +85,7 @@ pub async fn build_program( async fn get_cached_program( program_id: Uuid, path: &Path, + config: &Config, env: &Environment, ) -> Result, BuildProgramError> { if !fs::try_exists(path.join("ok")).await? { @@ -98,6 +100,7 @@ async fn get_cached_program( }; Ok(Some(BuildResult { program_id, + ttl: config.program_ttl, compile_result, })) } diff --git a/src/schemas/programs.rs b/src/schemas/programs.rs index 37dda3e..235b762 100644 --- a/src/schemas/programs.rs +++ b/src/schemas/programs.rs @@ -82,6 +82,8 @@ pub struct LimitsOpt { pub struct BuildRunResult { /// A unique identifier of the program that was built. pub program_id: Uuid, + /// The number of seconds after the last execution of the program before it is removed. + pub ttl: u64, /// The results of compiling the program. Empty iff programs don't need to be compiled in this /// environment. pub build: Option, @@ -94,6 +96,8 @@ pub struct BuildRunResult { pub struct BuildResult { /// A unique identifier of the program that was built. pub program_id: Uuid, + /// The number of seconds after the last execution of the program before it is removed. + pub ttl: u64, /// The results of compiling the program. Empty iff programs don't need to be compiled in this /// environment. pub compile_result: Option, diff --git a/tests/api.rs b/tests/api.rs index 3924448..06088c8 100644 --- a/tests/api.rs +++ b/tests/api.rs @@ -160,6 +160,7 @@ fn test_build_cached() { let BuildRunResult { program_id, + ttl: _, build, run, }: BuildRunResult = build_and_run(&request).unwrap();