Skip to content

Commit

Permalink
Include program ttl in responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Defelo committed Apr 22, 2023
1 parent d9c7427 commit 6865a0e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/api/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl ProgramsApi {
let (
BuildResult {
program_id,
ttl,
compile_result,
},
read_guard,
Expand Down Expand Up @@ -77,6 +78,7 @@ impl ProgramsApi {
{
Ok(run_result) => BuildRun::ok(BuildRunResult {
program_id,
ttl,
build: compile_result,
run: run_result,
}),
Expand Down
7 changes: 5 additions & 2 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand All @@ -67,6 +67,7 @@ pub async fn build_program(
Ok((
BuildResult {
program_id: id,
ttl: config.program_ttl,
compile_result: result,
},
_guard.downgrade(),
Expand All @@ -84,6 +85,7 @@ pub async fn build_program(
async fn get_cached_program(
program_id: Uuid,
path: &Path,
config: &Config,
env: &Environment,
) -> Result<Option<BuildResult>, BuildProgramError> {
if !fs::try_exists(path.join("ok")).await? {
Expand All @@ -98,6 +100,7 @@ async fn get_cached_program(
};
Ok(Some(BuildResult {
program_id,
ttl: config.program_ttl,
compile_result,
}))
}
Expand Down
4 changes: 4 additions & 0 deletions src/schemas/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RunResult>,
Expand All @@ -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<RunResult>,
Expand Down
1 change: 1 addition & 0 deletions tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ fn test_build_cached() {

let BuildRunResult {
program_id,
ttl: _,
build,
run,
}: BuildRunResult = build_and_run(&request).unwrap();
Expand Down

0 comments on commit 6865a0e

Please sign in to comment.