Skip to content

Commit

Permalink
timeout streams that already ended after a minute
Browse files Browse the repository at this point in the history
  • Loading branch information
DolceTriade committed Feb 2, 2024
1 parent f8f6a93 commit 8ead3f8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
27 changes: 27 additions & 0 deletions blade/bep/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,33 @@ impl publish_build_event_server::PublishBuildEvent for BuildEventService {
if session_uuid.is_empty() {
session_uuid = uuid.clone();
log::info!("{}: Stream started", session_uuid);
let mut already_over = false;
if let Ok(mut db) = global.db_manager.as_ref().get() {
if let Ok(inv) = db.get_shallow_invocation(&session_uuid) {
if let Some(end) = inv.end {
if std::time::SystemTime::now()
.duration_since(end)
.unwrap_or(std::time::Duration::from_secs(0))
> std::time::Duration::from_secs(60)
{
already_over = true;
}
}
}
}
if already_over {
log::warn!("{}: session already ended", session_uuid);

let _ = tx
.send(Err(Status::new(
tonic::Code::FailedPrecondition,
"session already ended",
)))
.await
.ok();
return;
}

if let Ok(mut db) = global.db_manager.as_ref().get() {
let _ = db
.update_shallow_invocation(
Expand Down
11 changes: 11 additions & 0 deletions blade/db/postgres/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ impl state::DB for Postgres {
.context("failed to get progress")
}

fn get_shallow_invocation(
&mut self,
invocation_id: &str,
) -> anyhow::Result<state::InvocationResults> {
schema::invocations::table
.select(models::Invocation::as_select())
.filter(schema::invocations::id.eq(invocation_id))
.get_result(&mut self.conn)
.map(|res| res.into_state())
.context("failed to get shallow invocation")
}
fn update_target_result(
&mut self,
invocation_id: &str,
Expand Down
12 changes: 12 additions & 0 deletions blade/db/sqlite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ impl state::DB for Sqlite {
.context("failed to get progress")
}

fn get_shallow_invocation(
&mut self,
invocation_id: &str,
) -> anyhow::Result<state::InvocationResults> {
schema::Invocations::table
.select(models::Invocation::as_select())
.filter(schema::Invocations::id.eq(invocation_id))
.get_result(&mut self.conn)
.map(|res| res.into_state())
.context("failed to get shallow invocation")
}

fn update_target_result(
&mut self,
invocation_id: &str,
Expand Down
6 changes: 6 additions & 0 deletions blade/routes/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub fn Details() -> impl IntoView {
view! { <h3>Build Metadata</h3> }
}
>

<BuildMetadata md=opts.build_metadata/>
</AccordionItem>

Expand All @@ -61,6 +62,7 @@ pub fn Details() -> impl IntoView {
view! { <h3>Explicit Command Line</h3> }
}
>

<OptionsList opts=opts.explicit_cmd_line/>
</AccordionItem>
<AccordionItem
Expand All @@ -69,6 +71,7 @@ pub fn Details() -> impl IntoView {
view! { <h3>Command Line</h3> }
}
>

<OptionsList opts=opts.cmd_line/>
</AccordionItem>
<AccordionItem
Expand All @@ -77,6 +80,7 @@ pub fn Details() -> impl IntoView {
view! { <h3>Unstructured Command Line</h3> }
}
>

<OptionsList opts=opts.unstructured/>
</AccordionItem>
<AccordionItem
Expand All @@ -85,6 +89,7 @@ pub fn Details() -> impl IntoView {
view! { <h3>Explicit Startup Command Line</h3> }
}
>

<OptionsList opts=opts.explicit_startup/>
</AccordionItem>
<AccordionItem
Expand All @@ -93,6 +98,7 @@ pub fn Details() -> impl IntoView {
view! { <h3>Startup Command Line</h3> }
}
>

<OptionsList opts=opts.startup/>
</AccordionItem>

Expand Down
1 change: 1 addition & 0 deletions blade/state/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pub trait DB {
fn update_test_result(&mut self, invocation_id: &str, name: &str, status: Status, duration: std::time::Duration, num_runs: usize) -> anyhow::Result<()>;
fn upsert_test_run(&mut self, id: &str, test_id: &str, run: &TestRun) -> anyhow::Result<()>;
fn get_invocation(&mut self, id: &str) -> anyhow::Result<InvocationResults>;
fn get_shallow_invocation(&mut self, id: &str) -> anyhow::Result<InvocationResults>;
fn delete_invocation(&mut self, id: &str) -> anyhow::Result<()>;
fn delete_invocations_since(&mut self, ts: &std::time::SystemTime) -> anyhow::Result<usize>;
fn insert_options(&mut self, id: &str, options: &BuildOptions) -> anyhow::Result<()>;
Expand Down

0 comments on commit 8ead3f8

Please sign in to comment.