Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "3"
members = ["crates/*", "app"]

[workspace.package]
version = "0.2.22"
version = "0.2.23"
edition = "2024"
license = "Apache-2.0"
repository = "https://github.com/DocSpring/visualci"
Expand Down
17 changes: 17 additions & 0 deletions app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ VISUALCI_STRIPE_WEBHOOK_SECRET=
# The most gallery credits one project is charged in a day: images past it are served free.
# VISUALCI_GALLERY_DAILY_CREDITS=50000

######################################################################################################################
# Live updates
######################################################################################################################

# The most streams one web process keeps open at once.
# VISUALCI_LIVE_MAX_STREAMS=2000

# The most streams one person, project token or visitor's address keeps open in one web process.
# VISUALCI_LIVE_MAX_STREAMS_PER_PRINCIPAL=30

# The most streams following one build in one web process.
# VISUALCI_LIVE_MAX_STREAMS_PER_BUILD=100

# How long one stream lasts, in seconds. It then ends, and the browser or the CLI connects again, so access is checked
# again.
# VISUALCI_LIVE_STREAM_SECONDS=1800

######################################################################################################################
# Heartbeats
######################################################################################################################
Expand Down
24 changes: 24 additions & 0 deletions app/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub struct Config {
#[settings(nested)]
pub gallery: Gallery,
#[settings(nested)]
pub live: Live,
#[settings(nested)]
pub heartbeats: Heartbeats,
}

Expand Down Expand Up @@ -252,6 +254,27 @@ pub struct Gallery {
pub daily_credits: i64,
}

/// The server-sent event streams the build and project pages and the CLI's `--wait` follow. The limits are each web
/// process's own: a stream past one is refused with a 429, and the page or the CLI reads on its own instead. A stream
/// holds no database connection while it waits.
#[derive(Clone, Settings)]
#[settings(title = "Live updates")]
pub struct Live {
/// The most streams one web process keeps open at once.
#[env("VISUALCI_LIVE_MAX_STREAMS", default = 2000)]
pub max_streams: usize,
/// The most streams one person, project token or visitor's address keeps open in one web process.
#[env("VISUALCI_LIVE_MAX_STREAMS_PER_PRINCIPAL", default = 30)]
pub max_streams_per_principal: usize,
/// The most streams following one build in one web process.
#[env("VISUALCI_LIVE_MAX_STREAMS_PER_BUILD", default = 100)]
pub max_streams_per_build: usize,
/// How long one stream lasts, in seconds. It then ends, and the browser or the CLI connects again, so access is
/// checked again.
#[env("VISUALCI_LIVE_STREAM_SECONDS", default = 1800)]
pub stream_seconds: u64,
}

/// Each scheduled job pushes its result to a [Gatus](https://gatus.io) external endpoint, so a run that failed, or no
/// run at all, alerts. Each pair is the endpoint's URL and its token; a job without a URL pushes nothing.
#[derive(Clone, Settings)]
Expand Down Expand Up @@ -461,6 +484,7 @@ pub fn install(config: &mut laravel::config::Config, env: &laravel::config::Env)
.set(settings.stripe.clone())
.set(settings.cloudflare.clone())
.set(settings.gallery.clone())
.set(settings.live.clone())
.set(settings.heartbeats.clone())
.set(settings);
}
Expand Down
6 changes: 5 additions & 1 deletion app/src/domain/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ pub async fn run(build_id: i64, store: &BlobStore, renderer_version: &str) -> la
}
match result {
Ok(true) => finished(id, build.project_id).await?,
Ok(false) => tracing::debug!(build_id = id, "build waiting for renders"),
Ok(false) => {
tracing::debug!(build_id = id, "build waiting for renders");
// Some of its snapshots may have been compared: its page shows the progress
crate::live::tell(build.project_id, Some(id)).await;
}
Err(e) if e.is::<laravel::cache::LockTimeout>() => {
tracing::info!(build_id = id, "another run is processing the build; it runs it again when it's done");
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/http/api/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ pub async fn create(auth: Result<ApiProject, ApiError>, Body(params): Body<Creat
// task), so they don't sit "receiving" beside this one.
crate::domain::processing::expire_abandoned(Some(project.id)).await?;
let build = domain::create(&project, &params, creator).await.map_err(ApiError::from)?;
crate::live::tell(project.id, Some(build.id)).await;
Ok(BuildResponse::new(&build, &project, &organization)
.with_blocked(&build, &project, &organization)
.await?)
Expand Down Expand Up @@ -270,6 +271,7 @@ pub async fn finalize(
let build =
if was_receiving { crate::domain::processing::stop_if_out_of_credits(build).await? } else { build };
if was_receiving && build.state == "processing" {
crate::live::tell(project.id, Some(build.id)).await;
crate::jobs::process_build::ProcessBuild { build_id: build.id }.dispatch().await?;
} else if was_receiving && build.state == "failed" {
crate::events::BuildChanged { build_id: build.id }.dispatch().await?;
Expand Down
1 change: 1 addition & 0 deletions app/src/http/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub fn routes(route: &mut Router) {
route.post("/v1/support/feedback", support::feedback);
downloads::routes(route);
crate::auth::device::api_routes(route);
super::live::api_routes(route);
route.fallback(async || laravel::abort(404));
}

Expand Down
Loading
Loading