Skip to content

Commit

Permalink
show in-progress builds on build queue page
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Aug 1, 2024
1 parent e579f2d commit 98b8611
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 79 deletions.

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

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

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

1 change: 1 addition & 0 deletions migrations/20240624085737_build-status-idx.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP INDEX builds_build_status_idx;
1 change: 1 addition & 0 deletions migrations/20240624085737_build-status-idx.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE INDEX builds_build_status_idx ON builds USING btree (build_status ASC);
46 changes: 22 additions & 24 deletions src/web/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,24 @@ pub(crate) async fn build_list_json_handler(
get_builds(&mut conn, &name, &version)
.await?
.iter()
.map(|build| {
.filter_map(|build| {
if build.build_status == BuildStatus::InProgress {
return None;
}
// for backwards compatibility in this API, we
// * convert the build status to a boolean
// * already filter out in-progress builds
//
// even when we start showing in-progress builds in the UI,
// we might still not show them here for backwards
// compatibility.
serde_json::json!({
Some(serde_json::json!({
"id": build.id,
"rustc_version": build.rustc_version,
"docsrs_version": build.docsrs_version,
"build_status": build.build_status.is_success(),
"build_time": build.build_time,
})
}))
})
.collect::<Vec<_>>(),
),
Expand Down Expand Up @@ -255,8 +258,7 @@ async fn get_builds(
INNER JOIN crates ON releases.crate_id = crates.id
WHERE
crates.name = $1 AND
releases.version = $2 AND
builds.build_status != 'in_progress'
releases.version = $2
ORDER BY id DESC"#,
name,
version.to_string(),
Expand Down Expand Up @@ -558,29 +560,25 @@ mod tests {

let response = env.frontend().get("/crate/foo/0.1.0/builds").send()?;

// FIXME: temporarily we don't show in-progress releases anywhere, which means we don't
// show releases without builds anywhere.
assert_eq!(response.status(), StatusCode::NOT_FOUND);

// assert_cache_control(&response, CachePolicy::NoCaching, &env.config());
// let page = kuchikiki::parse_html().one(response.text()?);
assert_cache_control(&response, CachePolicy::NoCaching, &env.config());
let page = kuchikiki::parse_html().one(response.text()?);

// let rows: Vec<_> = page
// .select("ul > li a.release")
// .unwrap()
// .map(|row| row.text_contents())
// .collect();
let rows: Vec<_> = page
.select("ul > li a.release")
.unwrap()
.map(|row| row.text_contents())
.collect();

// assert!(rows.is_empty());
assert!(rows.is_empty());

// let warning = page
// .select_first(".warning")
// .expect("missing warning element")
// .text_contents();
let warning = page
.select_first(".warning")
.expect("missing warning element")
.text_contents();

// assert!(warning.contains("has not built"));
// assert!(warning.contains("queued"));
// assert!(warning.contains("open an issue"));
assert!(warning.contains("has not built"));
assert!(warning.contains("queued"));
assert!(warning.contains("open an issue"));

Ok(())
});
Expand Down
38 changes: 17 additions & 21 deletions src/web/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ pub(crate) async fn releases_for_crate(
FROM releases
INNER JOIN release_build_status ON releases.id = release_build_status.rid
WHERE
releases.crate_id = $1 AND
release_build_status.build_status != 'in_progress'"#,
releases.crate_id = $1"#,
crate_id,
)
.fetch(&mut *conn)
Expand Down Expand Up @@ -1292,25 +1291,22 @@ mod tests {
.create()?;

let response = env.frontend().get("/crate/foo/latest").send()?;
// FIXME: temporarily we don't show in-progress releases anywhere, which means we don't
// show releases without builds anywhere.
assert_eq!(response.status(), StatusCode::NOT_FOUND);

// let page = kuchikiki::parse_html().one(response.text()?);
// let link = page
// .select_first("a.pure-menu-link[href='/crate/foo/0.1.0']")
// .unwrap();

// assert_eq!(
// link.as_node()
// .as_element()
// .unwrap()
// .attributes
// .borrow()
// .get("title")
// .unwrap(),
// "foo-0.1.0 is currently being built"
// );

let page = kuchikiki::parse_html().one(response.text()?);
let link = page
.select_first("a.pure-menu-link[href='/crate/foo/0.1.0']")
.unwrap();

assert_eq!(
link.as_node()
.as_element()
.unwrap()
.attributes
.borrow()
.get("title")
.unwrap(),
"foo-0.1.0 is currently being built"
);

Ok(())
});
Expand Down
2 changes: 1 addition & 1 deletion src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ async fn match_version(
};

// when matching semver requirements, we only want to look at non-yanked releases.
let flt = |r: &&Release| r.yanked == Some(false);
let flt = |r: &&Release| r.yanked.is_none() || r.yanked == Some(false);

if let Some(release) = releases
.iter()
Expand Down
30 changes: 25 additions & 5 deletions src/web/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,8 @@ pub(crate) async fn activity_handler(mut conn: DbConnection) -> AxumResult<impl
struct BuildQueuePage {
description: &'static str,
queue: Vec<QueuedCrate>,
active_deployments: Vec<String>,
active_cdn_deployments: Vec<String>,
in_progress_builds: Vec<(String, String)>,
csp_nonce: String,
}

Expand All @@ -823,8 +824,9 @@ impl BuildQueuePage {
pub(crate) async fn build_queue_handler(
Extension(build_queue): Extension<Arc<BuildQueue>>,
Extension(pool): Extension<Pool>,
mut conn: DbConnection,
) -> AxumResult<impl IntoResponse> {
let (queue, active_deployments) = spawn_blocking(move || {
let (queue, active_cdn_deployments) = spawn_blocking(move || {
let mut queue = build_queue.queued_crates()?;
for krate in queue.iter_mut() {
// The priority here is inverted: in the database if a crate has a higher priority it
Expand All @@ -850,10 +852,28 @@ pub(crate) async fn build_queue_handler(
})
.await?;

let in_progress_builds: Vec<(String, String)> = sqlx::query!(
r#"SELECT
crates.name,
releases.version
FROM builds
INNER JOIN releases ON releases.id = builds.rid
INNER JOIN crates ON releases.crate_id = crates.id
WHERE
builds.build_status = 'in_progress'
ORDER BY builds.id ASC"#
)
.fetch_all(&mut *conn)
.await?
.into_iter()
.map(|rec| (rec.name, rec.version))
.collect();

Ok(BuildQueuePage {
description: "crate documentation scheduled to build & deploy",
queue,
active_deployments,
active_cdn_deployments,
in_progress_builds,
csp_nonce: String::new(),
})
}
Expand Down Expand Up @@ -1725,9 +1745,9 @@ mod tests {

let empty = kuchikiki::parse_html().one(web.get("/releases/queue").send()?.text()?);
assert!(empty
.select(".release > strong")
.select(".release > div > strong")
.expect("missing heading")
.any(|el| el.text_contents().contains("active CDN deployments")));
.any(|el| dbg!(el.text_contents()).contains("active CDN deployments")));

let full = kuchikiki::parse_html().one(web.get("/releases/queue").send()?.text()?);
let items = full
Expand Down
9 changes: 8 additions & 1 deletion templates/crate/builds.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
<ul>
{%- for build in builds -%}
<li>
{%- if build.build_status != "in_progress" %}
<a href="/crate/{{ metadata.name }}/{{ metadata.version }}/builds/{{ build.id }}" class="release">
{%- else -%}
<div class="build-in-progress">
{%- endif %}
<div class="pure-g">
<div class="pure-u-1 pure-u-sm-1-24 build">
{%- if build.build_status == "success" -%}
Expand Down Expand Up @@ -74,12 +78,15 @@
{%- endif -%}
</div>
</div>
{%- if build.build_status != "in_progress" %}
</a>
{%- else -%}
</div>
{%- endif %}
</li>
{%- endfor -%}
</ul>
{%- else -%}
{# FIXME: temporarily this will never be shown since we hide in-progress releases for now #}
<div class="warning">
docs.rs has not built {{ metadata.name }}-{{ metadata.version }}
<br>
Expand Down
62 changes: 42 additions & 20 deletions templates/releases/build_queue.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,56 @@
{%- block body -%}
<div class="container">
<div class="recent-releases-container">
{%- if !active_deployments.is_empty() %}
<div class="release">
<strong>active CDN deployments</strong>
<div class="release pure-g">
<div class="pure-u-1-2">
<strong>currently being built</strong>
</div>
<div class="pure-u-1-2">
{%- if !active_cdn_deployments.is_empty() %}
<strong>active CDN deployments</strong>
{%- endif %}
</div>
</div>

<div class = "pure-g">
<div class="pure-u-1-2">
<ol class="queue-list">
{% for krate in active_deployments -%}
<li>
<a href="https://docs.rs/{{ krate }}">
{{ krate }}
</a>
</li>
{%- endfor %}
</ol>
{%- if !in_progress_builds.is_empty() %}
<ol class="queue-list">
{% for release in in_progress_builds -%}
<li>
<a href="/crate/{{ release.0 }}/{{ release.1 }}/builds">
{{ release.0 }} {{ release.1 }}
</a>
</li>
{%- endfor %}
</ol>
{%- else %}
<div class="about">
<p><strong>There is nothing currently being built</strong></p>
</div>
{%- endif %}
</div>
<div class="pure-u-1-2">
<div class="about">
<p>
After the build finishes it may take up to 20 minutes for all documentation
pages to be up-to-date and available to everybody.
</p>
<p>Especially <code>/latest/</code> URLs might be affected.</p>
</div>
{%- if !active_cdn_deployments.is_empty() %}
<ol class="queue-list">
{% for krate in active_cdn_deployments -%}
<li>
<a href="/{{ krate }}">
{{ krate }}
</a>
</li>
{%- endfor %}
</ol>
<div class="about">
<p>
After the build finishes it may take up to 20 minutes for all documentation
pages to be up-to-date and available to everybody.
</p>
<p>Especially <code>/latest/</code> URLs might be affected.</p>
</div>
{%- endif %}
</div>
</div>
{%- endif %}

<div class="release">
<strong>Build Queue</strong>
Expand Down
8 changes: 5 additions & 3 deletions templates/style/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ div.recent-releases-container {
background-color: var(--background-color);
}

.release {
.release, .build-in-progress {
display: block;
border-bottom: 1px solid var(--color-border);
padding: 0.4em $search-result-right-left-padding;
Expand All @@ -297,11 +297,13 @@ div.recent-releases-container {
}

.release:hover,
a.release:focus {
a.release:focus,
.build-in-progress:hover {
background-color: var(--color-background-code);
}

li:last-of-type .release {
li:last-of-type .release,
li:last-of-type .build-in-progress {
border-bottom: none;
}

Expand Down

0 comments on commit 98b8611

Please sign in to comment.