fc-common: format
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I946272ee6563f5bca0844c5a25ba08f66a6a6964
This commit is contained in:
parent
015360ffcf
commit
23a4a8e348
3 changed files with 25 additions and 33 deletions
|
|
@ -413,21 +413,21 @@ pub struct Channel {
|
|||
/// Remote builder for multi-machine / multi-arch builds.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
|
||||
pub struct RemoteBuilder {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub ssh_uri: String,
|
||||
pub systems: Vec<String>,
|
||||
pub max_jobs: i32,
|
||||
pub speed_factor: i32,
|
||||
pub supported_features: Vec<String>,
|
||||
pub mandatory_features: Vec<String>,
|
||||
pub enabled: bool,
|
||||
pub public_host_key: Option<String>,
|
||||
pub ssh_key_file: Option<String>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub consecutive_failures: i32,
|
||||
pub disabled_until: Option<DateTime<Utc>>,
|
||||
pub last_failure: Option<DateTime<Utc>>,
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub ssh_uri: String,
|
||||
pub systems: Vec<String>,
|
||||
pub max_jobs: i32,
|
||||
pub speed_factor: i32,
|
||||
pub supported_features: Vec<String>,
|
||||
pub mandatory_features: Vec<String>,
|
||||
pub enabled: bool,
|
||||
pub public_host_key: Option<String>,
|
||||
pub ssh_key_file: Option<String>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub consecutive_failures: i32,
|
||||
pub disabled_until: Option<DateTime<Utc>>,
|
||||
pub last_failure: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
/// User account for authentication and personalization
|
||||
|
|
|
|||
|
|
@ -387,11 +387,7 @@ pub async fn list_pinned_ids(
|
|||
}
|
||||
|
||||
/// Set the `keep` (GC pin) flag on a build.
|
||||
pub async fn set_keep(
|
||||
pool: &PgPool,
|
||||
id: Uuid,
|
||||
keep: bool,
|
||||
) -> Result<Build> {
|
||||
pub async fn set_keep(pool: &PgPool, id: Uuid, keep: bool) -> Result<Build> {
|
||||
sqlx::query_as::<_, Build>(
|
||||
"UPDATE builds SET keep = $1 WHERE id = $2 RETURNING *",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -77,8 +77,8 @@ pub async fn find_for_system(
|
|||
) -> Result<Vec<RemoteBuilder>> {
|
||||
sqlx::query_as::<_, RemoteBuilder>(
|
||||
"SELECT * FROM remote_builders WHERE enabled = true AND $1 = ANY(systems) \
|
||||
AND (disabled_until IS NULL OR disabled_until < NOW()) \
|
||||
ORDER BY speed_factor DESC",
|
||||
AND (disabled_until IS NULL OR disabled_until < NOW()) ORDER BY \
|
||||
speed_factor DESC",
|
||||
)
|
||||
.bind(system)
|
||||
.fetch_all(pool)
|
||||
|
|
@ -92,13 +92,11 @@ pub async fn find_for_system(
|
|||
/// Backoff formula (from Hydra): delta = 60 * 3^(min(failures, 4) - 1) seconds.
|
||||
pub async fn record_failure(pool: &PgPool, id: Uuid) -> Result<RemoteBuilder> {
|
||||
sqlx::query_as::<_, RemoteBuilder>(
|
||||
"UPDATE remote_builders SET \
|
||||
consecutive_failures = LEAST(consecutive_failures + 1, 4), \
|
||||
last_failure = NOW(), \
|
||||
disabled_until = NOW() + make_interval(secs => \
|
||||
60.0 * power(3, LEAST(consecutive_failures + 1, 4) - 1) + (random() * 30)::int \
|
||||
) \
|
||||
WHERE id = $1 RETURNING *",
|
||||
"UPDATE remote_builders SET consecutive_failures = \
|
||||
LEAST(consecutive_failures + 1, 4), last_failure = NOW(), disabled_until \
|
||||
= NOW() + make_interval(secs => 60.0 * power(3, \
|
||||
LEAST(consecutive_failures + 1, 4) - 1) + (random() * 30)::int ) WHERE \
|
||||
id = $1 RETURNING *",
|
||||
)
|
||||
.bind(id)
|
||||
.fetch_optional(pool)
|
||||
|
|
@ -110,10 +108,8 @@ pub async fn record_failure(pool: &PgPool, id: Uuid) -> Result<RemoteBuilder> {
|
|||
/// Resets consecutive_failures and clears disabled_until.
|
||||
pub async fn record_success(pool: &PgPool, id: Uuid) -> Result<RemoteBuilder> {
|
||||
sqlx::query_as::<_, RemoteBuilder>(
|
||||
"UPDATE remote_builders SET \
|
||||
consecutive_failures = 0, \
|
||||
disabled_until = NULL \
|
||||
WHERE id = $1 RETURNING *",
|
||||
"UPDATE remote_builders SET consecutive_failures = 0, disabled_until = \
|
||||
NULL WHERE id = $1 RETURNING *",
|
||||
)
|
||||
.bind(id)
|
||||
.fetch_optional(pool)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue