Skip to content
Open
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

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.

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.

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.

2 changes: 2 additions & 0 deletions migrations/20251211185514_add_duration_to_build.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Add down migration script here
ALTER TABLE build DROP COLUMN duration;
2 changes: 2 additions & 0 deletions migrations/20251211185514_add_duration_to_build.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Add up migration script here
ALTER TABLE build ADD COLUMN duration INTERVAL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, first time I see this (Postgre)SQL data type. Cute.

2 changes: 2 additions & 0 deletions src/bors/handlers/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ async fn maybe_complete_build(
};

db.update_build_status(&build, status).await?;
db.update_build_duration(&build, payload.running_time)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's modify the duration in the db.update_build_status call, to avoid doing two back-to-back SQL queries unnecessarily. I plan to extend the update_build_status function in the near future anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to add duration in db.update_build_status, but saw this function was used elsewhere which changes only status.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine, it can just be Option<Duration>.

.await?;
if let Some(trigger) = trigger {
handle_label_trigger(repo, pr_num, trigger).await?;
}
Expand Down
14 changes: 12 additions & 2 deletions src/database/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono::Duration;
use sqlx::PgPool;

use crate::bors::comment::CommentTag;
Expand All @@ -18,8 +19,9 @@ use super::operations::{
get_workflow_urls_for_build, get_workflows_for_build, insert_repo_if_not_exists,
record_tagged_bot_comment, set_pr_assignees, set_pr_mergeability_state, set_pr_priority,
set_pr_rollup, set_pr_status, unapprove_pull_request, undelegate_pull_request,
update_build_check_run_id, update_build_status, update_mergeable_states_by_base_branch,
update_pr_try_build_id, update_workflow_status, upsert_pull_request, upsert_repository,
update_build_check_run_id, update_build_duration, update_build_status,
update_mergeable_states_by_base_branch, update_pr_try_build_id, update_workflow_status,
upsert_pull_request, upsert_repository,
};
use super::{ApprovalInfo, DelegatedPermission, MergeableState, RunId, UpsertPullRequestParams};

Expand Down Expand Up @@ -233,6 +235,14 @@ impl PgDbClient {
update_build_status(&self.pool, build.id, status).await
}

pub async fn update_build_duration(
&self,
build: &BuildModel,
duration: Option<Duration>,
) -> anyhow::Result<()> {
update_build_duration(&self.pool, build.id, duration).await
}

pub async fn update_build_check_run_id(
&self,
build_id: i32,
Expand Down
19 changes: 19 additions & 0 deletions src/database/operations.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use chrono::DateTime;
use chrono::Duration;
use chrono::Utc;
use sqlx::postgres::PgExecutor;

Expand Down Expand Up @@ -631,6 +632,24 @@ pub(crate) async fn update_build_status(
.await
}

pub(crate) async fn update_build_duration(
executor: impl PgExecutor<'_>,
build_id: i32,
duration: Option<Duration>,
) -> anyhow::Result<()> {
measure_db_query("update_build_duration", || async {
sqlx::query!(
"UPDATE build SET duration = $1 WHERE id = $2",
duration as _,
build_id
)
.execute(executor)
.await?;
Ok(())
})
.await
}

pub(crate) async fn create_workflow(
executor: impl PgExecutor<'_>,
build_id: i32,
Expand Down
17 changes: 17 additions & 0 deletions tests/data/migrations/20251211185514_add_duration_to_build.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
UPDATE build
SET
duration = '3h 8m 37s'
WHERE
id = 1;

UPDATE build
SET
duration = '3h 11m 36s'
WHERE
id = 2;

UPDATE build
SET
duration = '3h 12m 15s'
WHERE
id = 3;